Ask Your Question
0

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

asked 2016-10-27 10:15:23 -0600

GPPK gravatar image

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;
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-10-27 11:24:15 -0600

berak gravatar image

updated 2016-10-27 11:42:51 -0600

imho, you should try the "multi-head" camera approach described here

VideoCapture cap(0); //a **single** capture instance

for (;;) {
    if (! cap.grab()) break; 
    Mat left,right;
    cap.retrieve(left, 0);
    cap.retrieve(right, 1);
}
edit flag offensive delete link more

Comments

Good idea, that only gives me the same frame from one camera though. This is very odd..

GPPK gravatar imageGPPK ( 2016-10-27 11:45:51 -0600 )edit

ah, shame ;(

sidenote, i was just about to buy something similar, so some personal interest in the outcome, here ;)

berak gravatar imageberak ( 2016-10-27 11:50:35 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-10-27 10:15:23 -0600

Seen: 371 times

Last updated: Oct 27 '16