cv :: findContours正在修改源图像OpenCV 2.3

时间:2012-09-25 18:16:51

标签: c++ opencv image-processing

从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有类似的结果?

1 个答案:

答案 0 :(得分:5)

错误! The docs明确指出:

  

图像由此功能修改。

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

相关问题