Oula Sawas Oula Sawas - 2 months ago 22
C++ Question

Opening my laptop camera with opencv

I'm trying to use my laptop camera with visual studio 2013 opencv.Here is my code:

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


When I run the code my camera doesn't open and it wouldn't give me any errors
Here's what I'm getting when I exit it using 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).`

Answer

Opencv window display it needs to add waitkey. In the provided code it should be under the while loop so that it can scan key every time and if key is not pressed within the delay it will continue till escape key is pressed.

Here is the working code:

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