1

I'm using opencv in VC2010 and I'm quite familiar with it.

I installed OPENCV 2.4.5 today and tried to display an image for testing if my opencv works or not.

it was amazing that this code displays the image in release mode but when I change the compiler mode to debug, opencv cannot find the image and returns null for image data !!!

#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
  int main()
 {  
    cv::RNG rng;
    cv::Mat image = cv::imread("1.jpg",-1);
    cv::imshow("Image",image);
    cv::waitKey(0);
return 0;
  }

the error is shown as :

OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupport
ed array type) in unknown function, file ..\..\..\src\opencv\modules\core\src\ar
ray.cpp, line 2482

I'm sure that in release Mode the code works fine , So the path, the image name and everything is fine but I don't know why it's not working in debug mode.

I also gave absolute path as input and it did not work either !! but again the absolute path worked on release mode !

it worth saying that I also tested my project both on 32bit and 64bit libraries of opencv and the problem did not change !!

PsP
  • 696
  • 3
  • 10
  • 34
  • If the debug executable is built in a different location from the release executable, you will need to copy your image file into the directory of the debug version. Either that, or pass an absolute path to `imread`. – Aurelius Jul 11 '13 at 17:44
  • @Aurelius I tested absolute path but it did not work either ... – PsP Jul 11 '13 at 18:32

1 Answers1

1

The debug version of your opencv library was probably compiled without support for "jpg" images. Also, see this answer

Make sure you did not mix up release and debug lib's of OpenCV when you linked libraries. Debug libraries have d at the end. Also, make sure that you are using the correct lib name based on the opencv version that you have, for example opencv_calib3d245d.lib

Community
  • 1
  • 1
Alexey
  • 5,898
  • 9
  • 44
  • 81
  • you mean debug version ? because I've got no problem with release version – PsP Jul 11 '13 at 20:29
  • I knew that debug and release libs differ in d but it was my fault to add "C:\opencv\build\x64\vc10\lib\*.lib" in "linker" settings this makes VC2010 to use all libs available in this folder and I think this caused the problem ! But thanks anyway – PsP Jul 11 '13 at 21:15