OpenCV cvLoadImage()是否无法在Visual Studio调试器中加载图像? [英] OpenCV cvLoadImage() does not load images in visual studio debugger?

查看:285
本文介绍了OpenCV cvLoadImage()是否无法在Visual Studio调试器中加载图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为OpenCV建立一个简单的hello世界,但是对于为什么它不起作用的想法已经不多了.

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;
}

我得到一个约200x200的灰色框,而不是所示的.jpg文件.如果使用其他jpg,则会得到相同类型的窗口,并且如果输入无效的文件名,则会得到非常小的窗口(预期).

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).

我正在Windows 7 Professional下使用Visual Studio 2008.

I am using Visual Studio 2008 under Windows 7 Professional.

大多数示例程序似乎都能正常工作,所以我感到困惑的是,该代码如何很好地加载示例jpg,但在上面的代码中却不起作用(甚至尝试了示例jpeg).

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).

通过编译产生的可执行文件运行良好,但是,无论文件位置是隐式的还是显式的,每次我尝试运行调试器时,Visual Studio 2008调试器都会将空指针加载到img中.

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.

推荐答案

myjpeg.jpg的路径似乎确实存在问题,因为在调试器下运行时,当前目录可能会有所不同.

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.

默认情况下,Visual Studio调试器使用的当前目录是包含.vcproj文件的目录,但是您可以在项目属性(调试->工作目录)中对其进行更改.

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).

您是否100%确定正确通过了绝对路径?尝试将相同的路径传递给fopen,看看它是否还返回NULL.如果是这样,则路径不正确.

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.

如果要确切查看要打开的库文件,可以使用 Project Monitor ,并在myjpeg.jpg上添加了过滤器.

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.

这篇关于OpenCV cvLoadImage()是否无法在Visual Studio调试器中加载图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆