How to use the deskew.determine_skew function in deskew

To help you get started, we’ve selected a few deskew examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sbrunner / deskew / tests / test_deskew.py View on Github external
def test_deskew(image, expected_angle):
    root_folder = 'results/{}'.format(image)
    if not os.path.exists(root_folder):
        os.makedirs(root_folder)

    image = io.imread(os.path.join(os.path.dirname(__file__), 'deskew-{}.png'.format(image)))
    grayscale = rgb2gray(image)
    angle = determine_skew(grayscale)
    print(angle - expected_angle.expected)
    assert angle == expected_angle
github sbrunner / deskew / deskew / cli.py View on Github external
def main() -> None:
    parser = argparse.ArgumentParser()

    parser.add_argument("-o", "--output", default=None, help="Output file name")
    parser.add_argument("--sigma", default=3.0, help="The use sigma")
    parser.add_argument("--num-peaks", default=20, help="The used num peaks")
    parser.add_argument("--background", help="The used background color")
    parser.add_argument(default=None, dest="input", help="Input file name")
    options = parser.parse_args()

    image = io.imread(options.input)
    grayscale = rgb2gray(image)
    angle = determine_skew(grayscale, sigma=options.sigma, num_peaks=options.num_peaks)
    if options.output is None:
        print("Estimated angle: {}".format(angle))
    else:
        if options.background:
            try:
                background = [int(c) for c in options.background.split(",")]
            except:  # pylint: disable=bare-except
                print("Wrong background color, should be r,g,b")
                sys.exit(1)
            rotated = rotate(image, angle, resize=True, cval=-1) * 255
            pos = np.where(rotated == -255)
            rotated[pos[0], pos[1], :] = background
        else:
            rotated = rotate(image, angle, resize=True) * 255
        io.imsave(options.output, rotated.astype(np.uint8))

deskew

Skew detection and correction in images containing text

MIT
Latest version published 4 months ago

Package Health Score

66 / 100
Full package analysis

Similar packages