Ask Your Question
0

Pass by reference errors

asked 2016-03-29 05:40:05 -0600

AVB gravatar image

Hi, I'm new to openCV and I've written the following code:

 void add_image(Mat &mat);

 int main() 
  {
        Mat mat = imread("img1.png", 1);
        add_image(mat); 
        imshow("Result", mat);
        waitKey(0);
        return 0;
  }

  void add_image(Mat &mat)
  {
        Mat logo = imread("img2.png", 1);
        logo.copyTo(mat(cv::Rect(0,0, logo.cols, logo.rows))); //Exception here
  }

On compilation I get the following error:

OpenCV Error: Assertion failed (!fixedSize()) in release, file /build/buildd/opencv-2.4.8+dfsg1/modules/core/src/matrix.cpp, line 1619 terminate called after throwing an instance of 'cv::Exception' what(): /build/buildd/opencv-2.4.8+dfsg1/modules/core/src/matrix.cpp:1619: error: (-215) !fixedSize() in function release

Aborted (core dumped)

How can I resolve this?

Regards,

A.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-03-29 05:48:31 -0600

You should first check if the images have been properly opened:

Mat img = imread("img1.png, IMREAD_COLOR);
if(img.empty()) throw std::runtime_error("unable to open the image");

The same apply for the logo. Feel free to replace the exception by whatever you want.

You should always check the boundaries of your images:

if( logo.rows <= mat.rows and logo.cols <= mat.cols)
    logo.copyTo(mat(Rect(0,0,logo.cols,logo.rows)

That should solve your issues.

edit flag offensive delete link more

Comments

Thank you! I followed both your steps and it is working now.

AVB gravatar imageAVB ( 2016-03-29 05:52:22 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-03-29 05:40:05 -0600

Seen: 3,186 times

Last updated: Mar 29 '16