Search code examples
pythonocrtesseractpython-tesseract

Tesseract OCR produces empty results


I need to extract digits from images (see sample images). I tried pytesseract but it is not working, it produces empty results. Below is the code I am using

Code

import pytesseract
import cv2

img = cv2.imread('image_path')
digits = pytesseract.image_to_string(img)
print(digits)

Sample Images

enter image description here

enter image description here

I have a large pool of images, as shown above. Tesseract is not working on any of them.


Solution

  • Try adding config --psm 7 (meaning Treat the image as a single text line.)

    import pytesseract
    import cv2
    img = cv2.imread('image_path')
    digits = pytesseract.image_to_string(img,config='--psm 7')
    print(digits)
    #'971101004900 1545'