How to extract text for processing by tesseract v4?

108 views
Skip to first unread message

Jason

unread,
May 7, 2019, 9:07:52 PM5/7/19
to tesseract-ocr
I have a problem with the current tesseract. I have documents that have sections of varying background and text colors. Ive read that tesseract v3 was white/black invariant and it didn't matter if I had white text on red background. But now it matters. The problem is, other parts in the same image are black text on white background. Tesseract 4 fails to identify the white text on red background at all. 

I have tried inverting the image colors so red (0xFF0000) becomes cyan (0x00FFFF) and the white text (0xFFFFFF) becomes black (0x000000). I then take the highest confidence text for the region. This improves some scenarios, but for the red/white scenario, does not work.

Questions:
1. How can I extract the text to be black and the background to be white, before using tesseract? 
2. Is there a way to configure tesseract to "just work"?

I've been trying to figure out how to do this for some time, and I haven't made any progress.



Lorenzo Bolzani

unread,
May 8, 2019, 3:57:47 AM5/8/19
to tesser...@googlegroups.com
Hi,
you can try a few things, but you need to write a small script (python, etc.) or use imagemagick. I suggest to first try with gimp, find what works best, and then write the code. You want dark text on clear background.

For white text on red:

1. Invert the image. Desaturate. Increase contrast.

2. split the image in RGB channels and use the one that looks better (red probably). Also try to decompose in HSV and see if S or V looks good. From gimp do: Colors -> components -> decompose.

3. invert the image and try thresholding (OTSU, etc.)

With a little programming you can identify and isolate black regions from white ones, but I do not know if this is something you want to do.


Post the image if this does not help.


Lorenzo

--
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 https://groups.google.com/group/tesseract-ocr.
To view this discussion on the web visit https://groups.google.com/d/msgid/tesseract-ocr/0c9cb359-bde4-4c2e-9643-1a9c56b639dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lorenzo Bolzani

unread,
May 20, 2019, 3:47:27 PM5/20/19
to tesser...@googlegroups.com

Jason Hihn

unread,
May 20, 2019, 8:59:19 PM5/20/19
to tesser...@googlegroups.com
That's very cool. Thanks!

You received this message because you are subscribed to a topic in the Google Groups "tesseract-ocr" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tesseract-ocr/Z9mFvYfTAJg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tesseract-oc...@googlegroups.com.

To post to this group, send email to tesser...@googlegroups.com.
Visit this group at https://groups.google.com/group/tesseract-ocr.
Reply all
Reply to author
Forward
0 new messages