imread not working in Opencv

I'm trying to use the imread function from OpenCV2.2.

My code is very simple.

cv::Mat host= imread("1.bmp", CV_LOAD_IMAGE_GRAYSCALE);

After that, the host matrix became filled by zeros pointers, i.e. an image has not loaded.

If I use cvLoadImage then it all works properly.

The file exists, and I am not mixing the release and debug libraries. Why imread doesn't work?


Reproduced with opencv 2.4.8.

If you are running in Debug, check that you are also using debug libraries, it fixed our problem. : OpenCV imread(filename) fails in debug mode when using release libraries.


i was facing the same problem with 2.4.6 . The reason was that while selecting the library , i had selected both the debug version and the release version. When i selected only the debug version for the library everything worked fine


I can confirm, that there are some problems with imread in OpenCV 2.2. However the problems only occurred on a Windows 32bit system. On a linux and on a mac it worked. I can't tell why it didn't work, but we had a small workaround for that.

We fixed this problem with the following macros, maybe you could try this out and use "ourImread" from then on.

#ifdef WIN32
#define ourImread(filename, isColor) cvLoadImage(filename.c_str(), isColor)
#else
#define ourImread(filename, isColor) imread(filename, isColor)
#endif