質問

私はOpenCVのシンプルなHello Worldを解決しようとしていますが、それが機能していない理由についてのアイデアが不足しています。

このコードをコンパイルして実行するとき:

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

指定された.jpgファイルの代わりに、約200x200の灰色のボックスを取得します。別のjpgを使用すると、同じ種類のウィンドウが表示され、無効なファイル名を入れた場合、非常に小さなウィンドウが表示されます(予想)。

Windows 7 Professionalの下でVisual Studio 2008を使用しています。

サンプルプログラムのほとんどは正常に動作しているように見えるため、そのコードがサンプルJPGを正常にロードする方法を二重に混乱させていますが、上記のコードでは機能しません(サンプルJPEGも試しました)。

アップデート

コンパイルによって生成された実行可能ファイルは正常に動作しますが、Visual Studio 2008デバッガーは、ファイルの場所が暗黙的か明示的かに関係なく、デバッガーを実行しようとするたびにIMGにヌルポインターをロードします。

役に立ちましたか?

解決

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.

他のヒント

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.

Try to add HAVE_JPEG into preprocessor definitions.

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top