Ask Your Question

haspemulator's profile - activity

2016-06-25 13:11:30 -0600 received badge  Famous Question (source)
2015-07-22 00:18:46 -0600 received badge  Student (source)
2015-03-06 10:20:03 -0600 received badge  Notable Question (source)
2014-08-26 12:17:23 -0600 received badge  Popular Question (source)
2013-09-07 11:38:45 -0600 received badge  Scholar (source)
2013-09-07 11:38:24 -0600 commented answer imread always return empty matrix

Thanks for the answer, it helped to solve the problem. Actually, the it was related to a wrong project setup (libs were from x64, project was x86). One little correction though: fopen() does set the errno on windows, just double checked that.

2013-09-07 06:03:07 -0600 received badge  Editor (source)
2013-09-07 05:23:30 -0600 asked a question 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