Ask Your Question
0

Assertion faild error on OpenCV3.3.0

asked 2017-08-29 23:48:14 -0600

rezaee gravatar image

updated 2017-08-29 23:52:45 -0600

I had this exact error message on windows 10 with VS2017 and OpenCV3.3.0 and couldn't find a solution. so switched to Ubuntu 16.04 and tried OpenCV3.3.0 with codeblocks. but I got the same error again!!

My code:

#include <iostream>
#include <opencv2/opencv.hpp>



using namespace std;
using namespace cv;

int main()
{

    Mat img=imread("home/m/1.jpg");
    namedWindow("image", WINDOW_AUTOSIZE);
    imshow("image", img);
    waitKey(0);
    return 0;
}

The error message:

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/m/opencv/modules/highgui/src/window.cpp, line 333
terminate called after throwing an instance of 'cv::Exception'
what(): /home/m/opencv/modules/highgui/src/window.cpp:333: error: (-215) size.width>0 && size.height>0 in function imshow

Aborted (core dumped)

Should I remove OpenCV3.3.0 and install 3.2.0 ?

edit retag flag offensive close merge delete

Comments

can you show your code, please ?

(that's a common error, usually your input img is empty.)

(NOT a bug, more a usage problem)

berak gravatar imageberak ( 2017-08-29 23:52:11 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-08-29 23:57:00 -0600

berak gravatar image

updated 2017-08-29 23:58:01 -0600

most probably, your image was not loaded due to a typo (user error)

try this:

Mat img=imread("/home/m/1.jpg"); // "/home", not "home" ??

if (img.empty()) { // only fools don't check...
     cerr << "image not loaded !" << endl;
     return -1;
}
edit flag offensive delete link more

Comments

Thank you, the problem solved by adding "/" before the home!

rezaee gravatar imagerezaee ( 2017-08-30 00:24:49 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-08-29 23:48:14 -0600

Seen: 754 times

Last updated: Aug 29 '17