我面临的问题是,当我运行opencv代码以检测图像中的轮廓时,我无法进入图像的边界内,因此该程序在图像的边界处获得了轮廓。
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();
图像输出看起来像这样:
我需要这样的东西:
最佳答案
我们为findContours
做white objects on black background
。
当您的二进制图像是black chars on white background
时,您应该使用标志threshold
对其进行THRESH_BINARY_INV
以获得黑底白字。然后执行findContours
。
关于opencv - 在白色背景上检测文本区域时,`cv::findContours`方法无法正常工作。 (OpenCV),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48314605/