Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Number detection from an image in python

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)

https://i.stack.imgur.com/BJMCF.png – the link to the 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 (link_threshold being an upper?): 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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading