Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV Error: Assertion failed (size.width>0 && size.height>0)

I compiled and installed the OpenCV libraries as per the official tutorial as well as the following link opencv-installation

I used the sample code provided in the official tutorial using eclipse cdt

#include <cv.h>
#include <highgui.h>

using namespace cv;

int main( int argc, char** argv )
{
  Mat image;
  image = imread( argv[1],1 );

  if( argc != 2 || !image.data )
  {
     printf( "No image data \n" );
     return -1;
  }

   namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
   imshow( "Display Image", image );

   waitKey(0);

   return 0;
}

Upon compiling i get the following error:

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/hp/apps/opencv-2.4.6.1/modules/highgui/src/window.cpp, line 261
terminate called after throwing an instance of 'cv::Exception'

what(): /home/hp/apps/opencv-2.4.6.1/modules/highgui/src/window.cpp:261: error: (-215) size.width>0 && size.height>0 in function imshow

Thanks in advance

like image 857
evolutionizer Avatar asked May 01 '26 07:05

evolutionizer


1 Answers

I had similar problem .You can add similar this code, maybe solve it. Because capture size cause this problem

VideoCapture cap;
cap.set(CV_CAP_PROP_FRAME_WIDTH, 640);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 480); 

cap.read(image);
like image 72
user2772836 Avatar answered May 04 '26 16:05

user2772836



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!