Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not recognize digit '7' #254

Closed
lagerfeuer opened this issue Sep 9, 2020 · 11 comments
Closed

Does not recognize digit '7' #254

lagerfeuer opened this issue Sep 9, 2020 · 11 comments

Comments

@lagerfeuer
Copy link

lagerfeuer commented Sep 9, 2020

I've been trying to read some Sudokus and so far all digits have been recognized except 7.
Is this a font issue maybe? All the images I have tried, no 7 was recognized.

Edit: Maybe related #130

Example:

Link to the image

 curl -o sudoku.png https://upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Sudoku-by-L2G-20050714.svg/1200px-Sudoku-by-L2G-20050714.svg.png
 easyocr -l en -f sudoku.png
([[42, 34], [100, 34], [100, 114], [42, 114]], '5', 0.9198901653289795)
([[174, 34], [234, 34], [234, 114], [174, 114]], '3', 0.5189616680145264)
([[704, 166], [762, 166], [762, 246], [704, 246]], '5', 0.8919380307197571)
([[44, 168], [104, 168], [104, 246], [44, 246]], '6', 0.8406975865364075)
([[568, 168], [630, 168], [630, 246], [568, 246]], '9', 0.7890614867210388)
([[445, 175], [499, 175], [499, 243], [445, 243]], '_', 0.8146840333938599)
([[176, 300], [234, 300], [234, 376], [176, 376]], '9', 0.8461765646934509)
([[968, 302], [1026, 302], [1026, 378], [968, 378]], '6', 0.9359095692634583)
([[44, 432], [102, 432], [102, 510], [44, 510]], '8', 0.9884797930717468)
([[1098, 432], [1156, 432], [1156, 510], [1098, 510]], '3', 0.5310271382331848)
([[572, 434], [630, 434], [630, 510], [572, 510]], '6', 0.9405879974365234)
([[46, 564], [108, 564], [108, 638], [46, 638]], '4', 0.6061235070228577)
([[702, 564], [762, 564], [762, 642], [702, 642]], '3', 0.617751955986023)
([[1100, 566], [1158, 566], [1158, 640], [1100, 640]], '_', 0.9189348220825195)
([[441, 569], [493, 569], [493, 637], [441, 637]], '8', 0.4214801788330078)
([[570, 694], [628, 694], [628, 772], [570, 772]], '2', 0.9453338384628296)
([[1098, 696], [1158, 696], [1158, 772], [1098, 772]], '6', 0.8925315737724304)
([[834, 826], [894, 826], [894, 906], [834, 906]], '2', 0.9729335308074951)
([[176, 830], [236, 830], [236, 906], [176, 906]], '6', 0.9366582036018372)
([[966, 830], [1024, 830], [1024, 904], [966, 904]], '8', 0.9889897704124451)
([[700, 956], [762, 956], [762, 1036], [700, 1036]], '9', 0.7338930368423462)
([[1098, 958], [1156, 958], [1156, 1036], [1098, 1036]], '5', 0.9352748394012451)
([[439, 961], [505, 961], [505, 1029], [439, 1029]], '4', 0.5053627490997314)
([[572, 962], [634, 962], [634, 1038], [572, 1038]], '_', 0.8581225872039795)
([[570, 1090], [630, 1090], [630, 1168], [570, 1168]], '8', 0.9891173839569092)
([[1096, 1090], [1154, 1090], [1154, 1166], [1096, 1166]], '9', 0.6340051293373108)
@rkcosmos
Copy link
Contributor

try using allowlist = '0123456789'

@lagerfeuer
Copy link
Author

@rkcosmos should have mentioned that I tried that, without success. Result is the same as above, minus the _ false positives.

@rkcosmos
Copy link
Contributor

one possible workaround is telling EasyOCR to use different model. For example, if you use
reader = easyocr.Reader(['ch_sim','en']), it's going to use simplified Chinese model. If reader = easyocr.Reader(['ru','en']), it's Cyrillic model. All models support number 0123456789 and they are trained with different data/font. One model might be better than other. Just remember to use allowlist.

Note that EasyOCR is probably too general for your use case. For Sudoku, there might be better open source digit recognition model.

@lagerfeuer
Copy link
Author

Tried both ch_sim and ru, neither worked. All of them seem to have a problem with the number 7.
Either that or it's the way the sevens appear in the Sudoku.

@poonyapat
Copy link

I tried reducing text_threshold to 0.5, using allowlist with 0-9, and blur with (3,3) kernel before OCR. Not sure why blurring help this issue but I tried and it worked.

@lagerfeuer
Copy link
Author

@poonyapat good suggestion. using your settings, 7 is recognized, but still not everything. playing around with the parameters might lead me to a satisfying result.

@haiderasad
Copy link

I tried reducing text_threshold to 0.5, using allowlist with 0-9, and blur with (3,3) kernel before OCR. Not sure why blurring help this issue but I tried and it worked.

how to set blur ? can you give example

@haiderasad
Copy link

try using allowlist = '0123456789'

can you please tell if you found the solution to recognize separate digits? it only recognizes digits which are combined with letters
image

@nuiva
Copy link

nuiva commented Jun 3, 2021

I also encountered this issue and blurring helped. Here's a full example.

test2.png
test2.png

import cv2          # opencv-python==4.5.2.52
import easyocr      # easyocr==1.3.2
img1 = cv2.imread("test2.png")
img2 = cv2.blur(img1, (3,3))
reader = easyocr.Reader(["en"])
results1 = reader.readtext(img1, allowlist="0123456789")
results2 = reader.readtext(img2, allowlist="0123456789")
print(results1) # []
print(results2) # [([[26, 0], [50, 0], [50, 30], [26, 30]], '7', 0.9999988079074598)]

@juanchosaravia
Copy link

I'm having a similar issue, here the image to recognize:
image

the result can't recognize there is a 7 there and it replaced 7 with a Z producing:
YLJ-BZM-WTG

@rkcosmos rkcosmos closed this as completed Mar 2, 2022
@beuaaa
Copy link
Contributor

beuaaa commented Oct 4, 2022

I also encountered this issue and mag_ratio=2 worked.

results = reader.readtext(img, mag_ratio=2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants