There’s any way to filter individual characters in a text with pattern in EasyOCR/PyTesseract using Python?

Good Afternoon brothers, I shall ask for an answer on this occasion because I’m confused and dazed by the error that I’m making. The question is quite simple: “How can I use different filters in a text with a pattern?”

I’m working with this specific pattern (X for Letter and 0 for Number): XXX0X00 (4 letters and 3 numbers, however, one of the letters is between the numbers)

I’ve never seen something that works like this in my Python classes, although my teacher has talked about many things that you could use with Python.

In reality, some of you’ll probably say: “But you can use EasyOCR and PyTesseract as normal, without these specific needs.”

Yeah, I could, but the font that EasyOCR is trying to detect has some weird slashes, like cuts, in some borders. Then “i” is similar to “1” or sometimes “J and L” and this happens with other specific letter or number interactions.

from easyocr import Reader
[All the other libraries and dependencies above]

img_path = "MyFolder\\7IDcode.jpg"
# The output text should be PLT1I50"

reader = Reader(['en'])
result_text = reader.readtext(img_path)
result_text

# The result was "PLT11SG"
# Because the 0 have a cut on his topside

Looking in some forums and sites, I’ve reached the conclusion that “you can create a new font by creating a dataset and making some .pth, .tiff, and .pty models,” but brothers, I really cannot comprehend how to do it, every example that I find uses Linux or a specific program, and I do not have “admin permission” to use some of those specific programs. If any of y’all can help me with any of those 2 questions, I’d be glad.

I’ve already tried with some ‘for’ and ‘if’ but haven’t succeeded at all.

result_text = ['PLT11SG']

letters = ['a', 'b', 'c'...]
numbers = ['1', '2', '3'...]
i = 0
position = result_text[i]
i += 1
if (position in letters == False) and (i <= 2):
    ... # use the filter
    else:
    ...
if (position in numbers == False) and (i = 3):
    ... # use the filter

# then repeat it in the other positions.

Leave a Comment