Ask Your Question
0

imshow: Assertion failed (size.width>0 && size.height>0) [closed]

asked 2015-06-23 15:01:15 -0600

Dr. Console gravatar image

updated 2015-06-23 15:02:19 -0600

Hey guys, here's the next error I encountered ... When I tried this code to test the installation:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;

int main()
{
    Mat image;// new blank image
    image = cv::imread("C:\\Users\XYZ\Documents\CodeBlocks\Projekte\Test\test.png", 0);// read the file
    namedWindow( "Display window", WINDOW_NORMAL );// create a window for display.
    imshow( "Display window", image );// show our image inside it.
    waitKey(0);// wait for a keystroke in the window
    return 0;
}

I get this error inside the app console:

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

This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.

Process returned 3 (0x3) execution time : 10.086 s Press any key to continue.

The image used is the standart Win7 demo picture of a jellyfish renamed to test.png and put into the project folder.

I hope that someone can help me, maybe it's just a change from opencv 2 to 3 but I don't know.

My System is Win7, Code::Blocks 13.12 and OpenCV 3. Compiler is mingw.

NG Dr. Console

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Dr. Console
close date 2015-06-24 04:12:12.891086

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-06-23 15:06:06 -0600

berak gravatar image

backslashes in fileneames...

either use forward ones:

"C:/Users/XYZ/Documents/CodeBlocks/Projekte/Test/test.png

or use double backslash (consistently):

"C:\\Users\\XYZ\\Documents\\CodeBlocks\\Projekte\\Test\\test.png
edit flag offensive delete link more

Comments

1

It is a good idea to always check for whether your image was opened. You should add a condition to check if ( image.empty() ) std::cerr << "Could not open file" << std::endl; return ( 1 ); just to avoid the exception you got.

unxnut gravatar imageunxnut ( 2015-06-23 15:22:41 -0600 )edit

Well this line throws an error at compiling XD cerr is not a member of std it says

Dr. Console gravatar imageDr. Console ( 2015-06-23 16:16:43 -0600 )edit

#include <iostream>

berak gravatar imageberak ( 2015-06-23 16:25:47 -0600 )edit

Well and in windows you have to have an eye on the filename if you reanme something, so my file was test.png.jpg and i didn't realized it -.-

Dr. Console gravatar imageDr. Console ( 2015-06-24 04:12:03 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-06-23 15:01:15 -0600

Seen: 36,616 times

Last updated: Jun 23 '15