18

I have got a problem with some basic OpenCV code. Here is my code:

 cv::Mat src;
 src=imread("Calibration.bmp",0);

 if (src.empty())
  cout << "Cannot load image" << " ";
 else
  cout << src.cols << " " << src.rows << " ";

Unfortunatelly cv::imread returns NULL matrix with any kind of input image (I have tried .bmp, .jpg). The filename seems to be working fine (program does not end with error), as using wrong filename generates an error message. I have tried using oldstyle "CvLoadImage" but same result occurred. Does anyone have any idea how to fix this?

Marcin
  • 1,104
  • 4
  • 17
  • 27

2 Answers2

25

Ok, I fixed the problem... Problem arises when you are mixing up release and debug OpenCV libs. I've changed paths and libs names in project properties and "cv::imread" works just fine.

Marcin
  • 1,104
  • 4
  • 17
  • 27
  • 9
    In your OpenCV\lib directory you should find two types of .lib files (for example: cv210.lib and cv210d.lib). If you are building your Solution in debug mode, in project properties you should link to the cv210d.lib, if you are building your solution in release mode, you should link to the cv210.lib. Same thing corresponds to dll files from OpenCV/bin dorectory. I hope it will help and sorry for not responding for a while:/ – Marcin Oct 14 '10 at 12:20
  • 1
    That's true, but why is this happening? Because other function work perfectly even if mixing libraries. Why this function? http://stackoverflow.com/q/9125817/744859 – Jav_Rock Feb 03 '12 at 10:50
  • 1
    Just saved me from a lot of headache. Thanks. – Aliostad Feb 08 '12 at 00:59
  • saved me a lot of headache too. a +1 to you @Marcin – Kimutai Sep 18 '14 at 13:17
  • Very Good! I just suggest you put the comment (with the details) inside the answer. – KansaiRobot Mar 25 '19 at 06:05
0

I had this behavior when trying to load an ARGB bitmap image (which I tried to load with color). Converting the bitmap to RGB (24bpp) solved the problem.

Philipp
  • 11,549
  • 8
  • 66
  • 126