OpenCV cvLoadImage() does not load images in visual studio debugger?

拜拜、爱过 提交于 2019-12-10 04:26:41

问题


I am trying to work out a simple hello world for OpenCV but am running out of ideas as to why it is not working.

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 grey box about 200x200 instead of the indicated .jpg file. If I use a different jpg I get the same kind of window, and if I put an invalid filename in, I get a very tiny window (expected).

I am using Visual Studio 2008 under Windows 7 Professional.

Most of the sample programs seem to work fine, so I am doubly confused how that code loads the sample jpgs just fine but in the code above it does not work (even tried the sample jpeg).

Update

The executables produced by compiling work fine, however the Visual Studio 2008 debugger loads a null pointer into img every time I try to run the debugger - regardless if the file location is implicit or explicit.


回答1:


It really seems like there's a problem with the path to myjpeg.jpg since the current directory could be different when you're running under the debugger.

By default, the current directory that the Visual Studio debugger uses is the directory containing the .vcproj file, but you can change it in the project properties (Debugging -> Working Directory).

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

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




回答2:


Which version of OpenCV are you using? I've tried your code on the latest (OpenCV2.0) and it works fine. You can download OpenCV2.0 from here.

If you want the latest build, you can get check it out with SVN from here.




回答3:


Try to add HAVE_JPEG into preprocessor definitions.




回答4:


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



来源:https://stackoverflow.com/questions/2115816/opencv-cvloadimage-does-not-load-images-in-visual-studio-debugger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!