Tesseract OCR

Tesseract is an open source text recognition (OCR) Engine. Tesseract can be used directly via command line, or (for programmers) by using an API to extract printed text from images.

Python-tesseract

Python-tesseract is an optical character recognition (OCR) tool for python. That is, it will recognize and “read” the text embedded in images.

Python-tesseract is a wrapper for Google’s Tesseract-OCR Engine. It is also useful as a stand-alone invocation script to tesseract, as it can read all image types supported by the Pillow and Leptonica imaging libraries, including jpeg, png, gif, bmp, tiff, and others. Additionally, if used as a script, Python-tesseract will print the recognized text instead of writing it to a file.

Example

Python-tesseract Example

from PIL import Image, ImageDraw, ImageFont
import pytesseract
from IPython.display import display
 
# Create a quick test image with text
img = Image.new("RGB", (300, 100), color=(255, 255, 255))
draw = ImageDraw.Draw(img)
draw.text((10, 40), "Hello, OCR!", fill=(0, 0, 0))
display(img)
 
# OCR
text = pytesseract.image_to_string(img)
print(text)