Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

imread always return empty matrix

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.

imread always return empty matrix

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.

Any information about getting more facts about the reason of image open failure is also appreciated.

imread always return empty matrix

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.

Any information about getting more facts about the reason of image open failure is also appreciated.

P.S. I've also tried the imdecode approach, but still no luck. Here's the code:

std::ifstream is(STATIC_PATH_TO_IMAGE, std::ios::binary);
std::vector<char> fileContents ((std::istreambuf_iterator<char>(is)), std::istreambuf_iterator<char>());
Mat tmp = imdecode(fileContents, IMREAD_GRAYSCALE); // same result, tmp.data == NULL
click to hide/show revision 4
hope you dont mind me removing the hash signs, since they only lead to annoying duplicates

updated 2013-09-07 08:10:07 -0600

berak gravatar image

imread always return empty matrix

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.

Any information about getting more facts about the reason of image open failure is also appreciated.

P.S. I've also tried the imdecode approach, but still no luck. Here's the code:

std::ifstream is(STATIC_PATH_TO_IMAGE, std::ios::binary);
std::vector<char> fileContents ((std::istreambuf_iterator<char>(is)), std::istreambuf_iterator<char>());
Mat tmp = imdecode(fileContents, IMREAD_GRAYSCALE); // same result, tmp.data == NULL