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
EDIT1: Microsoft LifeCam is my USB camera