Re: [tesseract-ocr] Help Using tesstrain for machine generated display

66 views
Skip to first unread message

Zdenko Podobny

unread,
Jul 8, 2023, 11:33:02 AM7/8/23
to tesser...@googlegroups.com
Have at https://github.com/tesseract-ocr/tesseract/issues/2342 and search for "tesseract OCR dot matrix", there are several suggestions on how to improve OCR results e.g. https://jeffreymorgan.io/articles/improve-dot-matrix-ocr-performance-tutorial/

PS: it does not make sense to post custom traineddata - there could be also a problem with how it was created/trained. 

Zdenko


ne 2. 7. 2023 o 11:27 Simon Plackett <plack...@gmail.com> napísal(a):
Hi, 
I have a display I would like to OCR - example image is at the bottom,
I have found a font that matches as far as I can tell exactly the number format
('5x7-dot-matrix') I have created 40k files similar to pil_image_10445.png with their corresponding .gt.txt files and created a new traineddata file.

My character set is limited to 0-9 and . 

I have tried using random sets of characters, and a more structured set nnnnn.nnn, the results from all of the traineddata files is poor. 

I have also tried turning the image to grayscale, cropping, enhancing the contrast etc to no avail. I am lucky to get 1 digit recognised. 

Bizarrely I get the same output no matter which input image file I use!!
(Using the attached traineddata file and the attached image I get 6.) - which is the same output for all the files I have tried.

I have stuck to either psm 7 or 13 as the others largely don't give any output

I would like some advice about whether continuing to increase the training data set will help, or any hints about trying to get better OCR success for these digits.

I am using tesseract 5.3.0 leptonica 1.83.0 on a debian 11 machine.
I built tesstrain as per the github instructions.

I am using ./tesseract -l dot_gas_int --psm 7 ~/tesstrain/data/dot_gas_int-ground-truth/pil_image_10445.png stdout

Apologies if I am doing something dumb, this is new to me and I am having a go :-)

Thanks
Simon


--
You received this message because you are subscribed to the Google Groups "tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tesseract-oc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tesseract-ocr/fa2232b3-852b-421e-939e-177971178faen%40googlegroups.com.

Simon Plackett

unread,
Jul 10, 2023, 8:48:07 AM7/10/23
to tesseract-ocr
Thank-you - the suggestions where perfect  - 
I have used pillow 9.5.0 to both blur and sharpen the image (as consecutive operations) which then is OCR'able reliably by tesseract. No need for anything custom.
I found changing contrast and brightness made no difference to the OCR outcome from tesseract.

For reference, here's a code snippet:
img_crop = img.crop((576, 224, 1274, 425))
img_gray = ImageOps.grayscale(img_crop)
img_blur = img_gray.filter(ImageFilter.GaussianBlur(6))
img_sharp = ImageEnhance.Sharpness(img_blur).enhance(3.5)

I found the most reliable values for blur and sharpen by iteration - took 30 mins at most to hone in on the values that are material.
Based on my images I used psm 7 and the digits qualifier.

tesseract --psm 7 image1_enh.png stdout digits

I have included the original and enhanced images for reference.

Thank-you again




image1_enh.png
image1.jpg
Reply all
Reply to author
Forward
0 new messages