用opencv打开我的笔记本电脑相机

时间:2016-09-20 04:35:00

标签: c++ opencv

我试图将我的笔记本电脑相机与visual studio 2013 opencv一起使用。这是我的代码:

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;    

int main(int argc, char** argv)
{
    char c = waitKey(1);
    Mat img;
    VideoCapture vc(0);
    while (1)
    {
        vc >> img;
        imshow("test", img);
        if (c == 27) //ESc
            break;
    }    
    return 0;
}

当我运行代码时,我的相机无法打开,它不会给我任何错误 这是我在使用ctrl + alt + dlt退出时获得的内容:

`Assignment1.exe' (Win32): Loaded 'C:\Users\oulas\Documents\Visual Studio 2013\Projects\Assignment1\Debug\Assignment1.exe'. Symbols loaded.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\kernel32.dll'
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Users\oulas\Documents\Visual Studio 2013\Projects\Assignment1\Debug\opencv_core249d.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Users\oulas\Documents\Visual Studio 2013\Projects\Assignment1\Debug\opencv_highgui249d.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp120d.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr120d.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\win32u.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32full.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\combase.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbase.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleaut32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp_win.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\avifil32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvfw32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shell32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.14393.0_none_88fef4c26039fb25\comctl32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\avicap32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msacm32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\windows.storage.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmm.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\powrprof.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmmbase.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shlwapi.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmmbase.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel.appcore.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\winmmbase.dll'
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\SHCore.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\profapi.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\uxtheme.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Program Files (x86)\Common Files\Microsoft Shared\Ink\tiptsf.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\clbcatq.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\devenum.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\setupapi.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntmarta.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\devobj.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wintrust.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msasn1.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\crypt32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msdmo.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\qcap.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\quartz.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcrypt.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msctf.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dwmapi.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\UIAutomationCore.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\userenv.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\mfksproxy.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\atl.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\mfplat.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\RTWorkQ.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\mfcore.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ksuser.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\mfperfhelper.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\FSClient.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\mfsensorgroup.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\avrt.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vidcap.ax'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\Kswdmcap.ax'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\mfc42.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\odbc32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dpapi.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\policymanager.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp110_win.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\mfreadwrite.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\qedit.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\comdlg32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\WinSxS\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.14393.187_none_bab139cc35912856\GdiPlus.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ddraw.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dciman32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\igdumdim32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\igc32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\d3dim700.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\igc32.dll'
'Assignment1.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\igdumdim32.dll'
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\igdumdim32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\igc32.dll'. Cannot find or open the PDB file.
'Assignment1.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\igc32.dll'
'Assignment1.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\igdumdim32.dll'
'Assignment1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msyuv.dll'. Cannot find or open the PDB file.
The thread 0x1950 has exited with code 1 (0x1).
The thread 0x574 has exited with code 1 (0x1).
The thread 0x2284 has exited with code 1 (0x1).
The thread 0x1fb0 has exited with code 1 (0x1).
The thread 0x8e0 has exited with code 1 (0x1).
The thread 0x1b3c has exited with code 1 (0x1).
The thread 0xc4 has exited with code 1 (0x1).
The thread 0xb18 has exited with code 1 (0x1).
The thread 0x1c78 has exited with code 1 (0x1).
The thread 0x23d8 has exited with code 1 (0x1).
The thread 0xed8 has exited with code 1 (0x1).
The thread 0x1b4c has exited with code 1 (0x1).
The thread 0x4a4 has exited with code 1 (0x1).
The thread 0xf2c has exited with code 1 (0x1).
The thread 0x1354 has exited with code 1 (0x1).
The thread 0x2258 has exited with code 1 (0x1).
The program '[5740] Assignment1.exe' has exited with code 1 (0x1).`

1 个答案:

答案 0 :(得分:1)

Opencv窗口显示需要添加waitkey。在提供的代码中,它应该在while循环下,以便它可以每次扫描键,如果在延迟内没有按下键,它将继续直到按下退出键。

以下是工作代码:

#include <iostream> 
#include <opencv2/core/core.hpp> 
#include <opencv2/highgui/highgui.hpp> 
#include <opencv2/imgproc/imgproc.hpp> 
using namespace cv;

int main(int argc, char** argv) 
{  

    Mat img;  
    VideoCapture vc(0); 
    while (1) 
    {
        char c = waitKey(1);  
        vc >> img;
        imshow("test", img);
        if (c == 27) //ESc
            break;
    }

   return 0;
}