3

I'm currently writing a script in python that requires the use of tesseract to read a number like this:

enter image description here

Using digits only and -psm 6 (or 7) it outputs 5.551

I have had some success with other numbers (5.700 works) but this particular number is giving me a ton of problems. Unfortunately i need a high degree of accuracy for my program but i thought tesseract would be able to decipher such a simple string.

I have also tried to use GOCR and that correctly read 6.881 (yay!) but gave the output 5._00 for 5.700 (boo!)

Any idea why it would be doing this?

Or more importantly, anything i can do to get around the problem ( preferably without having to train tesseract ).

Nigel B
  • 3,577
  • 3
  • 34
  • 52
Loocid
  • 6,112
  • 1
  • 24
  • 42

3 Answers3

2

I doubled its size and removed the transparency (replacing it with white) using Imagemagick (you can use something else if you want) and Tesseract OCR'd the enhanced image correctly:

$ convert I1Zau.png -background white -flatten -resize 200% I1Zau_2.png
$ tesseract I1Zau_2.png o.txt
$ cat o.txt.txt 
6.881
Karol S
  • 9,028
  • 2
  • 32
  • 45
  • Awesome, I will test it out with some more numbers and see what happens. – Loocid Nov 13 '13 at 15:30
  • 1
    @Loocid: I'd like to add that I've been also working with Tesseract recently and I discovered today that using Imagemagick to preprocess the files (removing compression artifacts and doubling the size) increases greatly the accuracy. – Karol S Nov 13 '13 at 18:40
1

Welcome to the world of OCR! Unfortunately even those simple cases can be problematic for a basic OCR application. One workaround I have used with some success is to actually make your image bigger (using imagemagick) and then feed into Tesseract. This only works up to a point. You could also try the standard gambit of morphological operations on the image.

Depending on your overall requirements (will the digits always be in this font/size, will the backgrounds be noisy etc...) You might want to manually make each digit a separate image to make sure that Tesseract can handle the fonttype you are using. If it cannot work on single digits it is unlikely to work on anything else you pass it.

Paul
  • 7,155
  • 8
  • 41
  • 40
  • 1
    The reverse worked for me: I needed top make the image _smaller_. – Cody Piersall Nov 13 '13 at 13:34
  • The numbers will always be in the same format as above, only with a variation in the number of digits (up to 5). I'll have a play around with imagemagick and see if I can find a setting that Tesseract likes. – Loocid Nov 13 '13 at 15:32
1

The image resolution is way too low. Simply rescaling to 300 DPI has produced the correct result for me.

nguyenq
  • 8,212
  • 1
  • 16
  • 16