OCR From Small Graphs

161 views
Skip to first unread message

Aaron G

unread,
Apr 22, 2015, 2:44:07 AM4/22/15
to tesser...@googlegroups.com
Hello - 

First, thank you to everyone supporting this tool...  I've had pretty good success with it in the past, but am running into an issue, I'm hoping someone may be able to help with.  I receive images similar to the attached, and based on what I have read, it sounds like tesseract may have issues with this type of test, but I'm wondering if anyone has any thoughts on the best way to pull the numbers out.

I've tried converting to grayscale, increasing density, etc...  but have not had any success.  I'm running tesseract 3.02 on Ubuntu 12.04.

Any help would be greatly appreciated.

Thanks,

Aaron
o.png

Art Rhyno.

unread,
Apr 22, 2015, 8:07:53 AM4/22/15
to tesser...@googlegroups.com

Maybe a few "select by color" loops to pull the numbers out on their own? I have done this kind of thing with gimp scripts but it could be done programmatically. This might be a case where you can make the colors work for you.

 

art

--
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 post to this group, send email to tesser...@googlegroups.com.
Visit this group at http://groups.google.com/group/tesseract-ocr.
To view this discussion on the web visit https://groups.google.com/d/msgid/tesseract-ocr/74c2f8d4-ace8-4993-be57-d2c72550e013%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dmitri Silaev

unread,
Apr 22, 2015, 11:50:36 AM4/22/15
to tesser...@googlegroups.com
What can be achieved with ImageMagick and scripts. I hope that wouldn't drive you nuts.

These steps more or less obvious:

- Source image
inet006.png

- To grayscale
inet006_gray.png

- Upscaled
inet006_gray_rs.png

- Thresholded
inet006_gray_rs_thld.png

Now something more complicated:

- Floodfill to expose numbers inside bars
inet006_gray_rs_thld_ffW.png
>convert inet006_gray_rs_thld.png -floodfill +0+0 white inet006_gray_rs_thld_ffW.png

- Remove numbers inside bars in thresholded image
inet006_B.png
>composite inet006_gray_rs_thld.png inet006_gray_rs_thld_ffW.png -compose Minus inet006_B.png

- Remove bars in thresholded image to expose numbers outside bars
>convert inet006_B.png -fill white -floodfill +620+1170 black inet006_B_ffW.png
inet006_B_ffW.png

- Combine numbers inside and outside bars into a single image
>composite inet006_B_ffW.png inet006_gray_rs_thld_ffW.png -compose Minus inet006_chars.png
inet006_chars.png

- Invert for morphology
inet006_chars_inv.png

- Denoise a bit for morphology to run better
>convert inet006_chars_inv.png -morphology Open Disk:1 inet006_chars_inv_denoise.png
inet006_chars_inv_denoise.png

- Morphology - Dilate to mark regions containing numbers (each can be of one or more characters)
>convert inet006_chars_inv_denoise.png -morphology Dilate Square:10 inet006_chars_inv_denoise_mdil.png
inet006_chars_inv_denoise_mdil.png

- Connected component (CC) labeling - to extract regions
>convert inet006_chars_inv_denoise_mdil.png -define connected-components:verbose=true -define connected-components:area-threshold=100 -connected-components 8 -auto-level -depth 8 inet006_regions.png
Output:
Objects (id: bounding-box centroid area mean-color):
  0: 1245x1245+0+0 621.8,621.7 1523291 gray(0)
  1: 99x81+561+53 611.0,93.1 7388 gray(255)
  10: 97x82+785+539 831.2,577.7 7052 gray(244)
  19: 56x82+1026+945 1054.3,986.3 4229 gray(255)
  20: 56x81+128+946 156.3,986.7 4163 gray(255)
  21: 55x81+355+986 382.0,1026.2 3902 gray(255)
"inet006_regions.png" here generated only for display purposes

- Here you need to use your favorite utilities to extract strings like "56x82+1026+945" (except for the first CC) and use them in a loop to crop the character regions from "inet006_chars.png":
>convert inet006_chars.png -crop 56x82+1026+945 inet006_reg1.png
>convert inet006_chars.png -crop 97x82+785+539 inet006_reg2.png
etc.
inet006_reg1.png, inet006_reg2.png

- Finally use Tess with textline PSM:
>tesseract.exe inet006_reg1.png inet006_reg1.png -psm 7
>tesseract.exe inet006_reg2.png inet006_reg2.png -psm 7
etc.
inet006_reg1.png.txt, inet006_reg2.png.txt

You can also sort regions by X to get the left to right reading order.

HTH

Best regards,
Dmitri Silaev
www.CustomOCR.com





--
inet006_reg1.png.txt
inet006_chars_inv_denoise.png
inet006_chars_inv_denoise_mdil.png
inet006_reg1.png
inet006_reg2.png
inet006_reg2.png.txt
inet006_regions.png
inet006_gray.png
inet006_gray_rs.png
inet006_gray_rs_thld.png
inet006_gray_rs_thld_ffW.png
inet006_B.png
inet006_B_ffW.png
inet006_chars.png
inet006_chars_inv.png

Aaron G

unread,
Apr 22, 2015, 7:23:36 PM4/22/15
to tesser...@googlegroups.com
Thanks for the suggestion, Art!  I very much appreciate it!

Aaron

Aaron G

unread,
Apr 25, 2015, 12:41:45 PM4/25/15
to tesser...@googlegroups.com
Thanks very much, for your expertise, and also for taking the time to work it out, and explain everything. I very much appreciate it!!

Have a great weekend!
Reply all
Reply to author
Forward
0 new messages