What is the difference between Pytesseract and Tesserocr?

From my experience Tesserocr is much faster than Pytesseract.

Tesserocr is a python wrapper aroung the Tesseract C++ API. Whereas pytesseract is a wrapper the tesseract-ocr CLI.

Therefore with Tesserocr you can load the model in the beginning or your program, and run the model seperately (for example in loops to process videos). With pytesseract, each time you call image_to_string function, it loads the model and process the image, therefore being slower for video processing.

To install tesserocr I just typed in the terminal pip install tesserocr.

To use tesserocr

import tesserocr
from PIL import Image
api = tesserocr.PyTessBaseAPI()
pil_image = Image.open('sample.jpg')
api.SetImage(pil_image)
text = api.GetUTF8Text()

To install pytesseract : pip install pytesseract.

To run it :

import pytesseract
import cv2
image = cv2.imread('sample.jpg')
text = pytesseract.image_to_string(image)  

pytesseract is only a binding for tesseract-ocr for Python. So, if you want to use tesseract-ocr in python code without using subprocess or os module for running command line tesseract-ocr commands, then you use pytesseract. But, in order to use it, you have to have a tesseract-ocr installed.

You can think of it this way. You need a tesseract-ocr installed because it's the program that actually runs and does the OCR. But, if you want to run it from python code as a function, you install pytesseract package that enables you to do that. So when you run pytesseract.image_to_string(Image.open('test-european.jpg'), lang='fra'), it calls the tesseract-ocr with the provided arguments. The results are the same as running tesseract test-european.jpg -l fra. So, you get the ability to call that from the code, but in the end, it still has to run the tesseract-ocr to do the actual OCR.


Pytesseract is a python "wrapper" for the tesseract binary. It offers only the following functions, along with specifying flags (man page):

  • get_tesseract_version Returns the Tesseract version installed in the system.
  • image_to_string Returns the result of a Tesseract OCR run on the image to string
  • image_to_boxes Returns result containing recognized characters and their box boundaries
  • image_to_data Returns result containing box boundaries, confidences, and other information. Requires Tesseract 3.05+. For more information, please check the Tesseract TSV documentation
  • image_to_osd Returns result containing information about orientation and script detection.

See the project description for more information.

On the other hand, tesserocr interfaces directly with Tesseract's C++ API (APIExample) which is much more flexible/complex and offers advanced features.