Ask Your Question

Assertion faild error on OpenCV3.3.0

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

rezaee gravatar image

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

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);
    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


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 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

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

berak gravatar image

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

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


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

rezaee gravatar imagerezaee ( 2017-08-30 00:24:49 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


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

Seen: 334 times

Last updated: Aug 29 '17