2013-02-12 117 views
1

編譯的OpenCV的源代碼和配置Windows 7和VS2010正確鏈接庫後,我就能夠編譯下面的代碼:OpenCV錯誤:「無法加載圖像!」

#include <opencv2/highgui/highgui.hpp> 
#include <iostream> 

using namespace cv; 
using namespace std; 
int main() 
{ 
    Mat im = imread("C:\projects\cvtest3\lena.jpg"); // this *is* the proper path, I'm sure 

    if (im.empty()) 
    { 

     cout << "Cannot load image!" << endl; 
       while (true){} 
     return -1; 
    } 
    imshow("Image", im); 
    waitKey(0); 
} 

即使正確指定的路徑我不能得到這個代碼顯示萊娜形象。這裏的代碼有什麼問題嗎?

雖然代碼編譯,這是完整的輸出,同時建設:

'cvtest3.exe': Loaded 'C:\projects\cvtest3\Debug\cvtest3.exe', Symbols loaded. 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Users\antonio\Documents\opencv_build_32bits\install\bin\opencv_core249d.dll', Symbols loaded. 
'cvtest3.exe': Loaded 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\bin\cudart32_50_35.dll', Binary was not built with debug information. 
'cvtest3.exe': Loaded 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\bin\npp32_50_35.dll', Binary was not built with debug information. 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Users\antonio\Documents\opencv_build_32bits\install\bin\opencv_highgui249d.dll', Symbols loaded. 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.17514_none_ec83dffa859149af\comctl32.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\avifil32.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\winmm.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\msacm32.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\msvfw32.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\shell32.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\shlwapi.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\avicap32.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\version.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file 
'cvtest3.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file 
The thread 'Win32 Thread' (0x2028) has exited with code -1073741510 (0xc000013a). 
+1

在路徑中使用斜槓,沒有反斜槓 – CharlesB 2013-02-13 00:28:30

回答

3

試試這個代碼:

#include <opencv2/highgui/highgui.hpp> 
#include <opencv2/core/core.hpp> 
#include <opencv2/imgproc/imgproc.hpp> 

using namespace std; 
using namespace cv; 

int main() 
{ 
    Mat image = imread("C:\\projects\\cvtest3\\lena.jpg"); 
    if(image.empty()) 
    return -1; 
    imshow("TEST",image); 
    waitKey(); 

    return 0; 
} 
  1. 嘗試使用的是2.4.3
  2. 最新的OpenCV鏈接正確的庫
  3. 正確添加包含路徑
  4. 將bin文件夾的路徑添加到環境變量路徑
+0

唯一缺少的是雙斜槓。我正在使用2.4.9,鏈接已正確完成。 爲什麼需要雙反斜槓? – andandandand 2013-02-13 00:49:52

+0

是現在工作的代碼...? – 2013-02-13 01:11:52

+0

是的,它工作 – andandandand 2013-02-14 02:01:26