multiple webcam test [closed]
So I have a usb logitech webcam and a built in laptop webcam. I am trying to start both the webcam at same time. I made a demo code below to test but cap2 object keep failing to open. Do any you guys have a suggestion. cap is the default which is the logitech webcam and cap2 is the built in web cap.
#include <iostream>
#include <opencv2\highgui\highgui.hpp>
#include <string>
int main(int arg, char * args[])
{
cv::VideoCapture cap, cap2;
cv::Mat mat1;
cv::Mat mat2;
cap.open(0);
cap2.open(1);
if(!cap.isOpened())
return -1;
if(!cap2.isOpened())
return -2;
cv::namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
cv::namedWindow("MyVideo2",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo2"
while(true)
{
cap.read(mat1);
cap2.read(mat2);
cv::imshow("MyVideo",mat1);
cv::imshow("MyVideo2", mat2);
}
cap.release();
cap2.release();
return 0;
}
And actually this is a duplicate of http://answers.opencv.org/question/24368/openning-multiple-webcam/ ... please stick to a single question! You can update the question itself using edit button.