cv :: findContours正在修改源图像OpenCV 2.3 [英] cv::findContours is modifying source image OpenCV 2.3

查看:162
本文介绍了cv :: findContours正在修改源图像OpenCV 2.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

From OpenCV documentation, source image in cv::findContours is aquired as const, but something strange is going on with my application. I'm using cv::inRange function to get thresholded image over specific color, and after that, using cv::moments, I can get the center of white pixels in thresholded image and this is working ok.

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

In addition, I would like to implement the code for finding biggest contour and locating central moment in that contour. After adding just cv::findContours in the code, I spotted strange behavior in the output and after that I wanted to check what is going on with source image using this code:

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

After this, output is showing that there is a difference between threshedImage and contourImage. How this is possible? Does anyone have similar results with cv::findContours?

推荐答案

错误! 文档明确指出:

图像由此函数修改。

所以如果你需要原始图像完整,制作此图像的副本并将副本传递给 cv :: findContours()

So if you need the original image intact, make a copy of this image and pass the copy to cv::findContours().

这篇关于cv :: findContours正在修改源图像OpenCV 2.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆