/autocrop

A python package to crop smaller photos out of a larger image and optionally rotate crooked photos

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

This is a python package to crop smaller photos out of a larger image and
optionally rotate crooked photos.  The typical use would be to scan several
photos in a flatbed scanner, and use autocrop to find the photos, deskew them,
and save them independently.

Pipenv can be used to install dependencies (currently only pillow and numpy).

Basic usage of the package is as follows:

>>> from PIL import Image
>>> from autocrop import MultiPartImage, Background
>>> 
>>> # A saved scan with the scanner empty.
>>> blank_img = Image.open('/path/to/blank/scan')
>>> background = Background().load_from_image(blank_img, dpi=200)
>>> 
>>> # A saved scan with multiple photos loaded in the scanner
>>> scan_img = Image.open('/path/to/scanned/image')
>>> scan = MultiPartImage(scan_img, background, dpi=200)
>>> 
>>> for index, photo in enumerate(scan):
...     photo.save('/path/to/cropped/image-%d.jpg' % index)

Also included is a simple linux command-line script to initiate a scan and
handle the cropping.  It should be considered a demonstration of most of the
capabilities of the package, not a utility for general wide-spread use.