简体   繁体   English

如何使用 OpenCV 检测反转颜色(0 和 255)图像中的轮廓?

[英]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. *sample-output 只是一个插图,因为我在油漆内部进行,但最终“sample-output”是最终想要的 output。

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.我希望您想使用 tesseract 将其转换为文本。 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.稍后进行 tesseract 时可能会导致问题,但这取决于图像的质量。 If your purpose of doing contour is to identify the text, i think is better you refer to this link .如果你做轮廓的目的是识别文本,我认为你最好参考这个链接 It gives better result.它给出了更好的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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