g++函数匹配与OpenCV 2.3.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在有问题的行上,语句
img(img_rowrange,img_colrange)
创建一个新的cv::Mat
。编译器不允许您在将其作为参数传递时执行此操作,因为由于您没有将其分配给变量,因此您将永远无法检索数据。所以尝试做这样的事情:
On the offending line, the statement
img(img_rowrange,img_colrange)
creates a newcv::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: