Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

multiple cameras

Hi All.

I would like to connect 6 cameras to my PC. In OpenGL, I have no problems (used openframeworks in codeblocks). In Opencv I can connect to each camera sequentially, or even 2 simultaneously, however I cannot get a live feed from all 6 at the same time. 1 or 2 of the cameras may still display an image (after long delays), while the others remain blank. I suspect a bug in opencv. Anyone out there with a solution? I suspect that internally they buffers are clashing, the frames not updating or something similar. Code below.

include <opencv2 opencv.hpp="">

int main() { //initialize and allocate memory to load the video stream from camera cv::VideoCapture camera0(0); cv::VideoCapture camera1(4); cv::VideoCapture camera2(5);

if( !camera0.isOpened() ) return 1;
if( !camera1.isOpened() ) return 1;
if( !camera2.isOpened() ) return 1;


while(true) {
    //grab and retrieve each frames of the video sequentially
    cv::Mat3b frame0;
    camera0 >> frame0;
    cv::Mat3b frame1;
    camera1 >> frame1;
    cv::Mat3b frame2;
    camera2 >> frame2;

    cv::imshow("Video0", frame0);
    cv::imshow("Video1", frame1);
    cv::imshow("Video2", frame2);

    //wait for 40 milliseconds
    int c = cvWaitKey(100);

    //exit the loop if user press "Esc" key  (ASCII value of "Esc" is 27)
    if(27 == char(c)) break;
}

return 0;

}

click to hide/show revision 2
added code tags

multiple cameras

Hi All.

I would like to connect 6 cameras to my PC. In OpenGL, I have no problems (used openframeworks in codeblocks). In Opencv I can connect to each camera sequentially, or even 2 simultaneously, however I cannot get a live feed from all 6 at the same time. 1 or 2 of the cameras may still display an image (after long delays), while the others remain blank. I suspect a bug in opencv. Anyone out there with a solution? I suspect that internally they buffers are clashing, the frames not updating or something similar. Code below.

include <opencv2 opencv.hpp="">

#include <opencv2/opencv.hpp>

int main()
{
    //initialize and allocate memory to load the video stream from camera
    cv::VideoCapture camera0(0);
    cv::VideoCapture camera1(4);
    cv::VideoCapture camera2(5);

camera2(5);

    if( !camera0.isOpened() ) return 1;
 if( !camera1.isOpened() ) return 1;
 if( !camera2.isOpened() ) return 1;


 while(true) {
     //grab and retrieve each frames of the video sequentially
     cv::Mat3b frame0;
     camera0 >> frame0;
     cv::Mat3b frame1;
     camera1 >> frame1;
     cv::Mat3b frame2;
     camera2 >> frame2;

     cv::imshow("Video0", frame0);
     cv::imshow("Video1", frame1);
     cv::imshow("Video2", frame2);

     //wait for 40 milliseconds
     int c = cvWaitKey(100);

     //exit the loop if user press "Esc" key  (ASCII value of "Esc" is 27)
     if(27 == char(c)) break;
 }

 return 0;
}

}