【问题标题】:cv::findContours is modifying source image OpenCV 2.3cv::findContours 正在修改源图像 OpenCV 2.3
【发布时间】:2012-09-17 07:34:53
【问题描述】:

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

【问题讨论】:

  • 它确实修改了...所以用 cvCopy 复制图像然后使用...

标签: c++ opencv image-processing


【解决方案1】:

错了!The docsclear 声明:

图片被这个函数修改了。

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

【讨论】:

  • 感谢您的信息,没有注意到。
猜你喜欢
  • 2011-12-31
  • 1970-01-01
  • 1970-01-01
  • 2017-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-24
  • 1970-01-01
相关资源
最近更新 更多