Ask Your Question

Pass by reference errors

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

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);
        imshow("Result", mat);
        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?



edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

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

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)

That should solve your issues.

edit flag offensive delete link more


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

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

Question Tools

1 follower


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

Seen: 2,547 times

Last updated: Mar 29 '16