Ask Your Question

Revision history [back]

OpenCV cheap stereo camera can't load both streams at once

I have purchased an ELP-1MP2CAM001 which shows up as two webcam devices on Windows. If I open the Windwos default "Camera" app and Skype I can display the feeds from both the left and right camera at the same time. I don't think therefore it is a USB Bandwidth issue with two cameras coming into the same port

I'm using fairly standard code (shown below) to open both of these feeds and it works successfully if I use two standard Microsoft HD3000 webcams instead of the single stereo camera.

I've tried a range of numbers inside the cap2() arguments so I don't think it's hiding at number 10 or anything weird like that.

My questions are:

  1. There must be some sort of on board hub for the ELP cameras, do I need to do something different in OpenCV?
  2. Could it be that both frames are accessible through cap(0)? This seems unlikely to me.
  3. This questions says I don't need to do anything special? but obviously I'm missing something.

Any help on this would be great.


Code:

#include <opencv2/opencv.hpp>

using namespace cv;

int main(int, char**)
{


    VideoCapture cap(0); // open the default camera
    VideoCapture cap2(1); // open the default camera

    cap.set(CV_CAP_PROP_FRAME_WIDTH, 240);
    cap.set(CV_CAP_PROP_FRAME_HEIGHT, 120);

    cap2.set(CV_CAP_PROP_FRAME_WIDTH, 240);
    cap2.set(CV_CAP_PROP_FRAME_HEIGHT, 120);

    if (!cap.isOpened())  // check if we succeeded
        return -1;

    if (!cap2.isOpened())  // check if we succeeded
        return -1;

    Mat frame;
    Mat frame2;
    namedWindow("Frame", 1);
    namedWindow("Frame2", 1);

    for (;;)
    {
        Mat frame;
        cap >> frame; // get a new frame from camera
        imshow("Frame", frame);

        Mat frame2;
        cap2 >> frame2;
        imshow("Frame2", frame2);





        if (waitKey(30) >= 0) break; // Finish on "esc" key
    }
    // the camera will be deinitialized automatically in VideoCapture destructor
    return 0;
}