OpenCV cvLoadImage () not loading images in visual studio debugger?

I'm trying to develop a simple welcome world for OpenCV, but I'm running out of ideas on why it doesn't work.

When I compile and run this code:

#include <cv.h> #include <highgui.h> int main(int argc, char* argv[]) { IplImage* img = cvLoadImage( "myjpeg.jpg" ); cvNamedWindow( "MyJPG", CV_WINDOW_AUTOSIZE ); cvShowImage("MyJPG", img); cvWaitKey(0); cvReleaseImage( &img ); cvDestroyWindow( "MyJPG" ); return 0; } 

I get a gray box about 200x200 in size instead of the specified .jpg file. If I use another jpg, I get the same window, and if I put an invalid file name, I get a very small window (expected).

I am using Visual Studio 2008 under Windows 7 Professional.

Most sample programs seem to work just fine, so I double-confuse how this code loads the jpg sample just fine, but in the code above it doesn't work (even tried the jpeg sample).

Update

Compiled executables work fine, however the Visual Studio 2008 debugger loads a null pointer into img every time I try to run the debugger - regardless of whether the file location is implicit or explicit.

+6
c ++ visual-studio-2008 opencv visual-studio-debugging
source share
4 answers

There seems to be a problem with the path to myjpeg.jpg , as the current directory may be different when you are working under the debugger.

By default, the current directory used by the Visual Studio debugger is the directory containing the .vcproj file, but you can change it in the project properties (Debug → Working directory).

Are you 100% sure that you have correctly traveled the absolute path? Try going the same way to fopen and see if it also returns NULL . If so, then the path is wrong.

If you want to see exactly which file the library is trying to open, you can use Project Monitor with a filter on myjpeg.jpg .

+8
source share

What version of OpenCV are you using? I tried my code on the latter (OpenCV2.0) and it works great. You can download OpenCV2.0 from here .

If you need the latest build, you can check it using SVN from here .

+1
source share

Try adding HAVE_JPEG to the preprocessor definitions.

0
source share

I ran into the same problem. The Debug version does not load the image, but when I compile and link it as Release, it works. Hope this helps

0
source share

All Articles