Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Dynamic display multiple video feed from multiple webcam

I have implemented code for capturing live video feed from webcam. But the code i have implemented is used 4 cams only. I want to make it dynamic. I.e: If i connect 2 webcam then it should display two windows with live feed. If i connect 3 cams then it should get 3 windows with live feed from all three cameras. I am getting the number of cameras being connected to the system using videoInput.h So now only part is how to make it dynamic for webcam. Here's the code.

int main(){

//Create matrix to store image
Mat image;
Mat image1;
Mat image2;
Mat image3;

//Mat image1;
//initailize capture
videoInput VI;
int numDevices = VI.listDevices();  
VideoCapture cap;
VideoCapture cap1;
VideoCapture cap2;
VideoCapture cap3;

bool x = false;
//VideoCapture cap1;;;;;

namedWindow("Camera 1",1);
namedWindow("Camera 2",1);
namedWindow("Camera 3",1);
namedWindow("Camera 4",1);

    //copy webcam stream to image
    cap >> image;
    cap1 >> image1;
    cap2 >> image2;
    cap3 >> image3;
    cap4 >> image4;
    //cap1 >> image1;
    imshow("Camera 1",image);
    imshow("Camera 2",image1);
    imshow("Camera 3",image2);
    imshow("Camera 4",image3);

    //imshow("Camera 2",image1);
    //delay 33ms