g++函数匹配与OpenCV 2.3.0

发布于 2024-11-30 22:19:46 字数 1210 浏览 0 评论 0原文

尝试编译以下 OpenCV 代码:

#include <opencv/cv.h>

int main(int argc,char *argv[])
{

    cv::Range img_rowrange, img_colrange, patch_rowrange, patch_colrange;

  img_rowrange.start=3;
  img_rowrange.end=6;
  img_colrange.start=2;
  img_colrange.end=5;

  patch_rowrange.start=0;
  patch_rowrange.end=3;
  patch_colrange.start=1;
  patch_colrange.end=4;

  cv::Mat img(10,10,CV_8UC1,cv::Scalar(1.0));
  cv::Mat patch(10,10,CV_8UC1,cv::Scalar(2.0));
  cv::Mat mask(10,10,CV_8UC1,cv::Scalar(3.0));

  patch(patch_rowrange,patch_colrange).copyTo(img(img_rowrange,img_colrange),mask(patch_rowrange,patch_colrange));


  return 0;
}

它在 Windows 下的 MSVS2010 中编译并运行良好,但在 g++ 和 MacOS 中出现以下错误:

gpp_cv_fail.cpp:22: 错误:没有匹配的函数可用于调用“cv::Mat::copyTo(cv::Mat, cv::Mat)” /usr/local/include/opencv2/core/core.hpp:1641: 注意:候选者是: void cv::Mat::copyTo(const cv::_OutputArray&) const /usr/local/include/opencv2/core/core.hpp:1643: 注意:void cv::Mat::copyTo(const cv::_OutputArray&, const cv::_InputArray&) const

有没有解决方法?据我了解,这是由于在 C++ 中处理临时对象和引用而发生的,但我找不到任何合适的解决方案(即在堆中分配补丁和掩码并不能解决它)

PS 我要做的是使用遮罩将一张图像应用到另一张图像上,这只是显示问题的一小段代码。

Trying to compile the following OpenCV code:

#include <opencv/cv.h>

int main(int argc,char *argv[])
{

    cv::Range img_rowrange, img_colrange, patch_rowrange, patch_colrange;

  img_rowrange.start=3;
  img_rowrange.end=6;
  img_colrange.start=2;
  img_colrange.end=5;

  patch_rowrange.start=0;
  patch_rowrange.end=3;
  patch_colrange.start=1;
  patch_colrange.end=4;

  cv::Mat img(10,10,CV_8UC1,cv::Scalar(1.0));
  cv::Mat patch(10,10,CV_8UC1,cv::Scalar(2.0));
  cv::Mat mask(10,10,CV_8UC1,cv::Scalar(3.0));

  patch(patch_rowrange,patch_colrange).copyTo(img(img_rowrange,img_colrange),mask(patch_rowrange,patch_colrange));


  return 0;
}

It compiles and works well in MSVS2010 under Windows, but with g++ and MacOS I get the following error:

gpp_cv_fail.cpp:22: error: no matching function for call to ‘cv::Mat::copyTo(cv::Mat, cv::Mat)’
/usr/local/include/opencv2/core/core.hpp:1641: note: candidates are: void cv::Mat::copyTo(const cv::_OutputArray&) const
/usr/local/include/opencv2/core/core.hpp:1643: note: void cv::Mat::copyTo(const cv::_OutputArray&, const cv::_InputArray&) const

Is there any workaround for it? As I understand, it happens due to handling of temporary objects and references in C++, but I cannot find any suitable solution for it (i.e. allocating the patch and mask in heap doesn't solve it)

P.S. What I was going to do is to apply one image over another using a mask, this is just the bit of code showing the problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清泪尽 2024-12-07 22:19:46

在有问题的行上,语句 img(img_rowrange,img_colrange) 创建一个新的 cv::Mat。编译器不允许您在将其作为参数传递时执行此操作,因为由于您没有将其分配给变量,因此您将永远无法检索数据。

所以尝试做这样的事情:

cv::Mat img_dst = img(img_rowrange,img_colrange);
patch(patch_rowrange,patch_colrange).copyTo(img_dst, mask(patch_rowrange,patch_colrange));

On the offending line, the statement img(img_rowrange,img_colrange) creates a new cv::Mat. The compiler does not let you do it while passing it as argument because as you are not assigning it to a variable, you will never be able to retrieve the data.

So try to do something like this:

cv::Mat img_dst = img(img_rowrange,img_colrange);
patch(patch_rowrange,patch_colrange).copyTo(img_dst, mask(patch_rowrange,patch_colrange));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文