Skip to content

Whitelist not working #4407

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

Open
kylefoley76 opened this issue Apr 2, 2025 · 3 comments
Open

Whitelist not working #4407

kylefoley76 opened this issue Apr 2, 2025 · 3 comments

Comments

@kylefoley76
Copy link

Current Behavior

I'm using Tesseract with Python because it's too difficult to OCR when the languages are mixed between the Greek alphabet and the Latin alphabet. Too often I will get Cyrillic characters as an output. I was hoping that the whitelist feature would solve that problem. But this is not the case. When I input the following whitelist,

αςερτυθιοπλκξηγφδσζχψωβνμΣΕΡΤΥΘΙΟΠΛΚΞΗΓΦΔΣΑΖΧΨΩΒΝΜΑΖΧΨΩΒΝΜABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890/?<>{}*&,;.:-+=|1234567890

I get a reasonably good output for the Latin characters, but the Greek text is not very accurate. for example, here is an output

Contracted nouns and adjectives in -ους from -οος 63
Adjectives of material in -ots from -εος 64
Nouns in ts, -εως and -υς/-υ, -εως 65

But the correct output should be οῦς not -ots

However, even if the accuracy were 100%, that whitelist will not solve my problem because it does not use the diacritics. So when I use a whitelist with diacritics, such as

"ΆᾺΑἉἊἍἋἌᾍᾈᾌᾎᾉAΒΔΗΉἩἨἮἯἬἫἭἪῌᾞᾟᾜᾘᾙῊἜἚἝἛἘἙΈΕΓΙῚἾἿἽἻἺἼἹἸΊIΚΧΞΛΜΝὩὨῼὭὫὬὪὯὮΩΏὉὈὊὋὌὍΟΌῸῺᾨᾩᾯᾮᾪᾫᾬᾭΠΦΨῬΡΣΤΘὝὛὙΎΥὟΖᾅᾳᾇᾄᾂᾀᾷᾆᾴᾲἇἆἂἄἅἃάᾶὰαἁἀααᾁᾃβδέὲἕἓἒἔἑἐεἠῆᾖἧᾔᾐᾑἥἣᾕἡἦῄῂῇᾗηῃήὴἤἢᾒᾓγϊῖιἰἶἴἲἱΐῒὶίἷἵἳῗιικχλμνὁᾦὀοῷὧωὠᾡὦῳῶὡᾠᾧῴῲὢὤὥὣᾤᾢὅὃὄὂόὸώὼᾣᾥπφψῤῥρςστθὖϋὗῧὐὑυῦὔὒύὺὓὕῢΰυυϝξζΑΖΧΨΩΒΝΜABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890/?<>{}*&,;.:-+=|1234567890 "

I get the output:

ΝΕΗΟΓΑΑΠΚ
Α
ΑΟΗΠΓΠΟΠ
ΑΟΕΠΓ
ΑΕΠΓΟ
ΑΠ
ἸΑΓΝΠΑΟΕΕ
ΡΟΡΟΠ
ΑΙΟΓΠΊ
ΠΟΙΠΕΟΓΠΓΕΠΟΏΡΒΡ
ΑΓ Ι
ΙΠΠΠΠΊΒΠ

I've tried locating the characters that are messing things up but there are too many. But it is certainly not any of these characters: /?<>{}*&,;.:-+=|

The image I'm trying to scan is uploaded. here is the exact python code I'm using:

import pytesseract
custom_oem_psm_config = '--oem 3 --psm 6 -c tessedit_char_whitelist="{}"'.format(
"ΆᾺΑἉἊἍἋἌᾍᾈᾌᾎᾉAΒΔΗΉἩἨἮἯἬἫἭἪῌᾞᾟᾜᾘᾙῊἜἚἝἛἘἙΈΕΓΙῚἾἿἽἻἺἼἹἸΊIΚΧΞΛΜΝὩὨῼὭὫὬὪὯὮΩΏὉὈὊὋὌὍΟΌῸῺᾨᾩᾯᾮᾪᾫᾬᾭΠΦΨῬΡΣΤΘὝὛὙΎΥὟΖᾅᾳᾇᾄᾂᾀᾷᾆᾴᾲἇἆἂἄἅἃάᾶὰαἁἀααᾁᾃβδέὲἕἓἒἔἑἐεἠῆᾖἧᾔᾐᾑἥἣᾕἡἦῄῂῇᾗηῃήὴἤἢᾒᾓγϊῖιἰἶἴἲἱΐῒὶίἷἵἳῗιικχλμνὁᾦὀοῷὧωὠᾡὦῳῶὡᾠᾧῴῲὢὤὥὣᾤᾢὅὃὄὂόὸώὼᾣᾥπφψῤῥρςστθὖϋὗῧὐὑυῦὔὒύὺὓὕῢΰυυϝξζΑΖΧΨΩΒΝΜABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890\/?<>{}[]()*&,;.:-+=| "
)
str4 = pytesseract.image_to_string(img1, config=custom_oem_psm_config,lang='eng+ell')
print(str4)

I'm using pytesseract 0.3.13 and I have tesseract 5.3.8 installed. Also chatgpt informs me that sometimes tessearact cannot handle large whitelists. if that is the case then i think it would be very easy to solve that problem.

Image

Expected Behavior

No response

Suggested Fix

No response

tesseract -v

No response

Operating System

No response

Other Operating System

No response

uname -a

No response

Compiler

No response

CPU

No response

Virtualization / Containers

No response

Other Information

No response

@amitdo
Copy link
Collaborator

amitdo commented Apr 3, 2025

As you found out yourself, currently the whitelist/blacklist feature does not work as expected with the lstm ocr engine. Also, the lang1+lang2 combo does not work well.

@amitdo
Copy link
Collaborator

amitdo commented Apr 3, 2025

If you only need Greek and English, you can try tesseract in.png out -l Greek.

https://github.com/tesseract-ocr/tessdata_best/tree/main/script

@CanadianHusky
Copy link

I have the same problem with german diacritics (umlaute) on windows command line.
There is no way that I could find that allows
-c tessedit_char_whitelist=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzÄÖÜßäöü0123456789
part of the problem is that default windows command line does not support utf8
but even from powershell terminal with chcp 65001 or separate config file, I could not get whitelist or blacklist to work properly.
Maybe an expert can look into this. It would make a great library even better.

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

No branches or pull requests

3 participants