Heisenberg
Heisenberg

Reputation: 111

To detect digits from an image using cv2 and python

I am trying to detect digits located inside a grid and to tell their positions in an image and don't know where to start. So any help is welcome. So far I have used GT Text software but it didn't solve the purpose. Any helper function, libraries, tutorials, links or anything is welcome.

Upvotes: 1

Views: 3263

Answers (1)

Imperssonator
Imperssonator

Reputation: 36

You should check out the pytesseract module:

https://pypi.python.org/pypi/pytesseract/0.1

It has a one-liner for what you're trying to do:

try:
    import Image
except ImportError:
    from PIL import Image
import pytesseract as tes

results = tes.image_to_string(Image.open('test.png'),boxes=True)

This will give you results, which has each digit and the image coordinates of its bounding box.

You will need to install PIL (python image library, pip install PIL) and the tesseract c library (brew install tesseract if you have homebrew..) so it's not super trivial but once you have it working, this is the most straight forward OCR in python, and requires no training whatsoever.

Upvotes: 1

Related Questions