How to open usb cam instead of webcam in VideoCapture?
I have a small issue I want to open my usb camera instead of my webcam. Here is my C++ code it is very simple because I am learning OpenCV at the moment.
// Device ID: xinput list
// Video Stream: ls -ltrh /dev/video*
#include <opencv2/opencv.hpp>
#include <iostream>
#define webCam 8
#define usbCam 17
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
//Open the default video camera
VideoCapture cap(usbCam);
// if not success, exit program
if (cap.isOpened() == false)
{
cout << "Cannot open the video camera" << endl;
cin.get(); //wait for any key press
return -1;
}
double dWidth = cap.get(CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
double dHeight = cap.get(CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
cout << "Resolution of the video : " << dWidth << " x " << dHeight << endl;
string window_name = "My Camera Feed";
namedWindow(window_name); //create a window called "My Camera Feed"
while (true)
{
Mat frame;
bool bSuccess = cap.read(frame); // read a new frame from video
//Breaking the while loop if the frames cannot be captured
if (bSuccess == false)
{
cout << "Video camera is disconnected" << endl;
cin.get(); //Wait for any key press
break;
}
//show the frame in the created window
imshow(window_name, frame);
//wait for for 10 ms until any key is pressed.
//If the 'Esc' key is pressed, break the while loop.
//If the any other key is pressed, continue the loop
//If any key is not pressed withing 10 ms, continue the loop
if (waitKey(10) == 27)
{
cout << "Esc key is pressed by user. Stoppig the video" << endl;
break;
}
}
return 0;
}
Here is my Device ID
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ SYNAPTICS Synaptics Large Touch Screen id=11 [slave pointer (2)]
⎜ ↳ SynPS/2 Synaptics TouchPad id=14 [slave pointer (2)]
⎜ ↳ Logitech M510 id=16 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Power Button id=6 [slave keyboard (3)]
↳ Video Bus id=7 [slave keyboard (3)]
↳ Video Bus id=8 [slave keyboard (3)]
↳ Power Button id=9 [slave keyboard (3)]
↳ Integrated_Webcam_HD: Integrate id=10 [slave keyboard (3)]
↳ Dell WMI hotkeys id=12 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=13 [slave keyboard (3)]
↳ DELL Wireless hotkeys id=15 [slave keyboard (3)]
↳ Microsoft LifeCam VX-5000: Micr id=17 [slave keyboard (3)]
↳ Lauro Cabral’s Keyboard id=18 [slave keyboard (3)]
↳ 10:4F:A8:85:B2:13 id=19 [slave keyboard (3)]
EDIT1: Microsoft LifeCam is my USB camera
please remove screenshot and put results as text.
instead of 8 and 17 try 0 and 1
Just updated
I did and doesnt work
What does it mean "doesn't work "? an error message or "Video camera is disconnected" ?
as in the code only opens the webcam instead of the usb camera regardless if the param is a 1,0.