GithubHelp home page GithubHelp logo

skylerburger / cropyble Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 65 KB

A class that allows a user to easily crop images of recognizable text.

Home Page: https://pypi.org/project/cropyble/

License: MIT License

Python 100.00%

cropyble's Introduction

Cropyble

Author: Skyler Burger Version: 1.2.1

Overview

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 ✨ my first package on PyPI ✨ and I welcome feedback. Feel free to submit issues if you spot an area that could use improvement.

Architecture

Packages

  • pillow: a Python package for manipulating images
  • pytesseract: Python bindings for Tesseract
  • tesseract: a command-line program and OCR engine

Getting Started

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 cropyble or preferably with a environment manager such as pipenv
  • Place the following import statement at the top of your file: from cropyble import Cropyble
  • Create Cropyble instances and get to cropping!

Example:

# 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.

API

  • Cropyble(input_path): Takes in a string representing the input image location. Cropyble runs OCR on the image using pytesseract and 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.

Change Log

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

  • Added __repr__ and __str__ magic methods to Cropyble class.
  • Added .get_box() and .get_words() methods to Cropyble class

01/07/20 - 1.2.1

  • Re-released to PyPI

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.