5
votes

i am using tesseract with python. It recognizes almost all of my images with 2 or more numbers or characteres. But tesseract can't recognizes image with only one number. I tried to use the command line, and it's giving me "empty page" as response.

I don't want to train tesseract with "only digits" because i am recognizing characters too.

What is the problem?

Below the image that its not recognized by tesseract.

enter image description here

Code:

 #getPng(pathImg, '3') -> creates the path to the figure.
 pytesseract.image_to_string( Image.open(getPng(pathImg, '3')) 
4
technically this isn't a python question as the python aspect of it seems to be working fine. You can try binarizing the image, making the text smaller. If the text is too big sometimes Tesseract can't identify the symbols.Srini
If would help, if you can show us what you have in terms of code so far. stackoverflow.com/help/mcvehikerjobs
@hikerjobs I added the code that i am using the tesseract.Luiza Rodrigues
@SrinivasSuresh i took off the "python" tag. In the case i tried to enlarge the image to see if improve something, i will try to make it smaller, as you suggest now.Luiza Rodrigues
@SrinivasSuresh, shrink the image didn't work.Luiza Rodrigues

4 Answers

7
votes

If you add the parameter --psm 13 it should works, because it will consider it as a raw text line, without searching for pages and paragraphs.

So try:

pytesseract.image_to_string(PATH, config="--psm 13") 
2
votes

Try converting image into gray-scale and then to binary image, then most probably it will read. If not duplicate the image , then you have 2 letters to read. So simply you can extract single letter

0
votes

Based on ceccoemi answer you could try other page segmentation modes (--psm flag).

For this special case I suggest using --psm 7 (single text line) or --psm 10 (single character):

psm7 = pytesseract.image_to_string(Image.open(getPng(pathImg, '3'), config='--psm 7')
psm10 = pytesseract.image_to_string(Image.open(getPng(pathImg, '3'), config='--psm 10')

More information about these modes can be found in the tesseract wiki.

0
votes

You can use -l osd for single digit like this.

tesseract VYO0C.png stdout -l osd --oem 3 --psm 6
2