Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6347169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:09:40+00:00 2026-05-24T21:09:40+00:00

Trying to compile the following OpenCV code: #include <opencv/cv.h> int main(int argc,char *argv[]) {

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:09:42+00:00Added an answer on May 24, 2026 at 9:09 pm

    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));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I am trying to compile the following code, #include <stdio.h> #include <string.h> int
I am trying to compile the following program: #include <iostream> int main(){ std::cout <<
When trying to compile the following code in LINQPad : void Main() { DriveInfo.GetDrives().Select(GetProviderName).Dump();
I am trying to compile the following code on Linux using gcc 4.2: #include
I'm trying to compile the following code in C++ string initialDecision () { char
I'm trying to compile the following snippet of code: #include <boost/filesystem/path.hpp> //Other includes snipped
When trying to compile the following code #include <thread> #include <iostream> void foo() {
I'm trying to compile the following minimal C code on ubuntu 10.10: #include <sys/capability.h>
When trying to compile the following code, I am getting a warning that line
I am trying to compile the following code: private String dataToString(){ Map data =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.