pythonocreasyocr

EasyOCR does not recognize this number in an image


I'm facing with the problem of detection a number from the image in python (the image contains the number five on the white background )

Im using the easyocr libary and opencv

Here is the sample of my code:

import cv2 #pip install opencv-python
import easyocr #pip install easyocr

img = cv2.imread('test.png')
reader = easyocr.Reader(['en'], gpu=True)
text = reader.readtext(img, allowlist ='0123456789')
print(text)

As I run the code I get [] when I need to get something like this:

[([[0, 11], [25, 11], [25, 29], [0, 29]], '5', 0.96162421524552115)]

(only an example this is not the exact thing that I need to get)

Image


Solution

  • There are a couple of parameters you can adjust when detecting using easyocr, see them all here in the documentation

    One of them, is "low_text" which in this case makes the detection work. I only briefly tested, and 0.3 gets the expected output:

    import cv2 #pip install opencv-python
    import easyocr #pip install easyocr
    
    img = cv2.imread('test.png')
    reader = easyocr.Reader(['en'])
    text = reader.readtext(img, allowlist ='0123456789', low_text=0.3)
    print(text)
    

    Outputs:

    [([[37, 7], [55, 7], [55, 31], [37, 31]], '5', 0.9999980926522767)]
    

    From the source-code, it seems this is used as a lower threshold: craft_utils.py:27

    There's an open issue here about explaining what it does: Question about these two parameters' difference: text_threshold and low_text