OCR selection based on colour

asked 2020-04-10 03:45:52 -0500

ajd gravatar image

Hi there, I'm just getting started with OpenCV via python and am very interested in seeing all the things that it's capable of.

My understanding, or at least problem solving in terms of image manipulation at the moment is a little lacking so i'm struggling to figure out the best way to approach this problem that i'm testing myself with.

From the image below (I added the blue boxes), i'm wanting to grab those sections of text (bounding boxes) to then feed into OCR via tesseract.

At the moment - i've tried making a mask using inrange based off the dark green behind "Yulong June", "picargo" etc and the bitwise_not the result - this makes "#7" "Yulong June" and "7.0" readable but I obviously lose the 3 at the beginning using this method because of the different background colour.

The background colour behind the 3 is the same colour as the #7, so if I mask that colour I lose the #7 (or the 3 on bitwise_not).

The image will not always be positioned the same way, it it scrollable down the page, so doing it by location won't work.

Does anyone have any solutions as to how to consistently find these sections in the image and have it in a format that will be well read by tesseract (all white text on black or all black text on white or similar)?

Any assistance you can give me with the direction to go with solving this would be amazing, i've done plenty of googling and can't figure it out.


Original Image

image description

Desired bounding boxes or images to send to tesseract

image description

this was my first mask

image description

and this is another mask I have been able to get - but I lose the #N

image description

edit retag flag offensive close merge delete