简体   繁体   中英

How to use OpenCV to detect contour in reversed color (0 and 255) image?

I have few images with black and white font color at the same page.

Sample-input

What I'm trying to do is to find the contour of each word in this image so it become like this.

Sample-output

*sample-output just an illustration since I do it inside paint, but ultimately "sample-output" is the final output wanted.

Before I start to find the contour, I need to do thresholding and cleaning then only proceed to find the contour for each word.
But I realized, after I did that the information inside the image start to missing.
If I do thresholding on black font, then the white font information is missing and vice versa.

Is there any way to preserve both information while doing thresholding and/or image processing?

i expecting you want to use tesseract to convert it into text. From the image you attached here i did tried to do threshold. It is very hard to get perfect result. It may cause issue when you do tesseract later but depends on the quality of the image. If your purpose of doing contour is to identify the text, i think is better you refer to this link . It gives better result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM