问题
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