检测白色背景上的文本区域时,`cv :: findContours`方法无法正常工作。 (OpenCV的) [英] `cv::findContours` method doesn't work properly when detect text regions on white background. (OpenCV)

查看:295
本文介绍了检测白色背景上的文本区域时,`cv :: findContours`方法无法正常工作。 (OpenCV的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临的问题是,当我运行opencv代码来检测图像中的轮廓时,我无法进入图像的边界,因此程序会在图像的边界上获得轮廓。

What problem I face is that when I run the opencv code to detect contours in an image,I can't get inside the boundary of the image and thus the program gets me a contour on the boundary of the image.

 Mat3b xyres;
cvtColor(img, xyres, COLOR_GRAY2BGR);
for (int i = 0; i < rects.size(); ++i)
{
    rectangle(xyres, rects[i], Scalar(0, 0, 255), 2);
}

Size size2(700, 800);
        resize(xyres, xyres, size2);
imshow("XY-Cut Result", xyres);

waitKey();

图像输出如下所示:

The image output looks something like this:

我需要这样的东西:

推荐答案

我们在黑色背景上为白色物体做 findContours

虽然你的二进制图像是白色背景上的黑色字符,你应该 threshold 带有标志 THRESH_BINARY_INV 以获得白色黑色。然后执行 findContours

While your binary image is black chars on white background, you should threshold it with flag THRESH_BINARY_INV to get white on black. Then do findContours.

这篇关于检测白色背景上的文本区域时,`cv :: findContours`方法无法正常工作。 (OpenCV的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆