I'm just starting with OpenCV and try to simply read the image (based on tutorial from http://opencv.org), but imread
always returns me the empty matrix. I'm pretty sure the file is okay, since I can open it in the same program with fopen
. I tried different jpg, png and bmp files, with same result. Here's the code:
int main( int argc, char** argv )
{
const char * STATIC_PATH_TO_IMAGE = "C:\\Pictures\\WP_20130809_14_30_52_Pro.jpg";
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
FILE* res = fopen(STATIC_PATH_TO_IMAGE, "rb");
cout << errno << endl; // errno == 0
fclose(res);
Mat image;
image = imread(STATIC_PATH_TO_IMAGE, IMREAD_UNCHANGED);
cout << errno << endl; // errno == 0
if(! image.data ) // image.data is always NULL
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE ); // 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'm using VS2012, Windows 8, OpenCV version 246.