`cv::findContours` method doesn't work properly when detect text regions on white background. (OpenCV)

南笙酒味 提交于 2019-12-24 21:07:13

问题


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:

I need something like this:


回答1:


We do findContours for white objects on black background.

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.



来源:https://stackoverflow.com/questions/48314605/cvfindcontours-method-doesnt-work-properly-when-detect-text-regions-on-whit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!