开发者

C++ OpenCV2 cv::Mat::copyTo error in linux

开发者 https://www.devze.com 2023-01-09 22:07 出处:网络
while trying to compile the following code in OpenCV2 in linux, cv::Mat image1, image2; cv::Rect rect1, rect开发者_JS百科2;

while trying to compile the following code in OpenCV2 in linux,

cv::Mat image1, image2;
cv::Rect rect1, rect开发者_JS百科2;
...
image1(rect1).copyTo(image2(rect2));

I get the following error:

x.cpp: In member function ‘cv::Mat Process(cv::Mat)’:

x.cpp:241: error: no matching function for call to ‘cv::Mat::copyTo(cv::Mat)’

cxcore.hpp:794: note: candidates are: void cv::Mat::copyTo(cv::Mat&) const

cxcore.hpp:796: note: void cv::Mat::copyTo(cv::Mat&, const cv::Mat&) const

Note: this code compiles and runs flawlessly in windows.

any help?


From what i see here, operator() for Mat needs an argument of type Mat and not Mat&. That seems to be the issue here.

Try adding a temporary objet of type Mat. See below.

cv::Mat image1, image2;
cv::Rect rect1, rect2;
...
cv::Mat extractedImage2 = image1(rect2);
image1(rect1).copyTo(extractedImage2);

But i must say i am no openCV expert, so that is just an answer based on my c++ knowledge.

0

精彩评论

暂无评论...
验证码 换一张
取 消