OpenCV Error: Assertion Failed (size.width>0 && size.height>0) in unknown function
I am new to OpenCV and I followed the first example in <<opencv 2="" computer="" vision="" application="" programming="" cookbook="">> with OpenCV 2.4.6.0, below is its code:
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
int main() {
//read an image
cv::Mat image = cv::imread("img.jpg");
//create image window named "My Image"
cv::namedWindow("My Image");
//show the image on window
cv::imshow("My Image", image);
//wait key for 5000ms
cv::waitKey(5000);
return 1;
}
The code could be compiled successfully and could be run by clicking the executable file in debug folder. But if I press the "F5" key to debug the project, it shows me this error in command windows when the code line runs to 'cv::imshow("My Image", image);' :
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in unknown function, file C:\opencv\modules\highgui\src\window.cpp, line 261
Finally I found if I change
cv::Mat image = cv::imread("img.jpg");
to
cv::Mat image = cv::imread("E:\\OpenCV\\OpenCVProjects\\myFirstOpenCVConsoleApp\\Debug\\img.jpg");
, no error exists. It seems it's a matter with the path of the image file, but I don't want to use absolute path here, could any one tell me what the wrong is with the path? Where could place the img.jpg would be right? Thanks in advance!