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

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

最佳答案

错了! The docs明确指出:

Source image is modified by this function.

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

关于c++ - cv::findContours 正在修改源图像 OpenCV 2.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12588801/

相关文章:

c++ - 对重载静态函数的模糊调用

c++ - 如何正确读取子进程的 stdout/stderr 输出?

Java:Eclipse 崩溃(Linux)

c++ - 使用 OpenCV 进行相机校准 - findChessboardCorners 返回 false

algorithm - 模拟 PhotoShop 的 "Color Range"算法

c++ - 为什么 std::extent 不能处理对像运算符 sizeof 这样的数组的引用?

c++ - 2D 独立游戏的最佳引擎是什么?

image - 访问图像像素值

python - 查找框和裁剪图像的角点

image-processing - JPEG 算法 - 用 Hadamard 变换替换 DCT