Cropyble is a module that allows a user to easily perform crops on an image containing recognizable text. This module utilizes optical character recognition (OCR) from Google by way of pytesseract.
Author: Skyler Burger Version: 1.2.1
Cropyble is a class that allows a user to easily perform crops on an image containing recognizable text. This class utilizes optical character recognition (OCR) with the assitance of Tesseract OCR and Pytesseract. Images containing clear, printed, non-decorative text work best with the OCR capabilities.
This is :sparkles: my first package on PyPI :sparkles: and I welcome feedback. Feel free to submit issues if you spot an area that could use improvement.
- pillow: a Python package for manipulating images
- pytesseract: Python bindings for Tesseract
- tesseract: a command-line program and OCR engine
Linux & Mac OS
- This class requires an additional piece of software that is not available through PyPI. Install tesseract on your machine with
sudo apt-get install tesseract-ocr
- Install Cropyble with either
pip3 install cropybleor preferably with a environment manager such as
- Place the following import statement at the top of your file:
from cropyble import Cropyble
- Create Cropyble instances and get to cropping!
# example.py from cropyble import Cropyble my_img = Cropyble('demo.jpg') my_img.crop('world', 'output.jpg')
In the above example, imagine that
demo.jpg is an image that contains the words 'hello world' and is located in the same directory as
example.py. An instance of Cropyble is created with a path to the input image. Cropyble then performs OCR on the image and stores information regarding the characters and words recognized, as well as their bounding boxes, within the instance of the class. By calling the
.crop() method of the instance with a word contained in the image and a path to an output file, a cropped image of the word is created. The output file is created if it does not exist, or is overwritten if it already exists.
- Cropyble(input_path): Takes in a string representing the input image location. Cropyble runs OCR on the image using
pytesseractand stores the bounding boxes for recognized words and characters for future crops.
- .crop(word, output_path): Takes in a string representing the word or character you'd like cropped from the image and a second string representing the output image path. Generates a cropped copy of the query text from the original image and saves it at the specified location.
- .get_box(word): Takes in a string representing a word that was recognized in the image. Returns a tuple representing the bounding box of the word in the format (x1, y1, x2, y2). The origin (0, 0) for images is located in the top-left corner of the image.
- .get_words(): Returns a list of words that were recognized within the input image.
07/22/2019 - 0.1.0
- Corrected bounding box math. Images are being properly cropped.
07/27/2019 - 0.2.0
- Refactored cropping functions into a class to minimize work needed to perform multiple crops on a single image.
07/30/2019 - 0.3.0
- Cropyble can now accept a path for the input image and crop() accepts a path for the output image.
08/02/2019 - 1.1.0
- Cropyble can now crop words and characters recognized within an image using the same crop() method.
10/08/19 - 1.1.4
- Refactored for packaging
- Uploaded to PyPI, bumpy ride
01/06/20 - 1.2.0
__str__magic methods to Cropyble class.
.get_words()methods to Cropyble class
01/07/20 - 1.2.1
- Re-released to PyPI
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size cropyble-1.2.0.tar.gz (4.1 kB)||File type Source||Python version None||Upload date||Hashes View hashes|