7

从 OpenCV 文档中, cv::findContours 中的源图像被获取为const,但是我的应用程序发生了一些奇怪的事情。我正在使用 cv::inRange 函数来获取特定颜色的阈值图像,之后,使用 cv::moments,我可以获得阈值图像中白色像素的中心,这可以正常工作。

另外,我想实现代码来查找最大轮廓并在该轮廓中定位中心矩。在代码中仅添加 cv::findContours 后,我在输出中发现了奇怪的行为,之后我想使用以下代码检查源图像的情况:

cv::Mat contourImage;
threshedImage.copyTo(contourImage); // threshedImage is the output from inRange
cv::findContours(threshedImage, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE, cv::Point(0,0));
cv::Mat temp;
cv::absdiff(threshedImage,contourOutput, temp);
cv::namedWindow("absdiff");
cv::imshow("absdiff",temp);

在此之后,输出显示 threshedImage 和 contourImage 之间存在差异。这怎么可能?有人对 cv::findContours 有类似的结果吗?

4

1 回答 1

5

错误的! 文档明确指出:

图像由该函数修改。

因此,如果您需要完整的原始图像,请复制此图像并将副本传递给 cv::findContours().

于 2012-09-25T18:59:04.590 回答