Ask Your Question
1

Minoru 3d: How to run 2 cameras simultaneously?

asked 2016-04-21 17:42:34 -0600

User gravatar image

updated 2020-11-19 00:46:43 -0600

use Minoru 3D stereocamera and want to capture images from left and right camera at the same time with OpenCV. I use Windows 7 64 bit

I have tried all solutions that I found in web, trying it with minoru drivers from CD and without.I try at 640x480 resolution with fps 15, even 5. I tried with standart OpenCV VideoCapture and also with videoInput library. But no one gives the expected result.

How can I run 2 Minoru cameras simultaneously?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
5

answered 2016-04-23 06:12:25 -0600

pklab gravatar image

updated 2016-04-28 03:13:17 -0600

This cam doesn't support synchronization between left and right... from specs: L/R shutters don’t synchronize(Max deviation 16.5 ms)

So you will have minimum 15.6 ms of delay between images. To get the best from your cam you could use 2 grabbing threads but it would be really complicated to keep sync.

Considered your hardware I would suggest to use standard grabbing loop with grab() and retrieve() sequence instead of >> or read()... from the doc: The primary use of the grab() function is in multi-camera environments, especially when the cameras do not have hardware synchronization

EDIT about transfer rate

You can't get 2 color cams 640x480@30fs on same USB2 port because transfer rate is too high for a single USB2 connection.

For 1 cam you need:

transferRate = 3chan * width * height * fps/BytesForMByte = 3*640*480*30/1024^2 = 26.37MB/s

Because the 2 cams share same USB port your requirement is 52MB/s.

Theoretical max speed for USB2 is 480Mbit/s (60MByte/s). Real speed depends on controller quality, on data packet overhead and if it's shared with other devices (hubs, keyboard, mouse,...). In addition, common USB2 is half duplex so receiving delays transmission and reverse. On my experience, typical transfer rate for USB2 is less than 35MB/s. That's why it doesn't work.

Conclusion: to use a stereo cam on a single USB2 connection we have to reduce data (lower resolution or fps or channels)... let me try to reduce fps:

maxFps <= (maxUsbSpeed * 1024^2) / (cams*3chan*width*height)
maxFps <= (35 * 1024^2) / (2*3*640*480) <= 19fps

Below is a sample code to grab from 2 cams and save the mosaic video file

void Main_GrabFrom2CamWriteMosaic()
{
    // SELECT CAM ID FOR YOUR CAMS
    int camL = 0, camR = 1;
    // CHOOSE YOUR BEST DRIVER
    int driver = CV_CAP_DSHOW; //use DSHOW or VFW or MSMF
    // OPEN THE DEVICES
    VideoCapture capL(camL + driver);
    VideoCapture capR(camR+ driver);
    //check if we succeeded
    if (! (capL.isOpened() && capR.isOpened())) {
        cerr << "Unable to open the cameras" << endl;
        capL.release(); capR.release();
        return;
    }
    //SET SAME SETTINGS ON BOTH CAM
    Size frameSize(640, 480);
    double fps = 15;

    capL.set(CV_CAP_PROP_FRAME_WIDTH, frameSize.width);
    capL.set(CV_CAP_PROP_FRAME_HEIGHT, frameSize.height);
    capL.set(CV_CAP_PROP_FPS, fps); //desired  FPS 

    capR.set(CV_CAP_PROP_FRAME_WIDTH, frameSize.width);
    capR.set(CV_CAP_PROP_FRAME_HEIGHT, frameSize.height);
    capR.set(CV_CAP_PROP_FPS, fps); //desired  FPS 

    // GRAB ONCE TO GET FRAME INFO (we'll lost this frames)
    Mat imgL, imgR;
    if (!(capL.read(imgL) && capR.read(imgR))) {
        std::cerr << "Unable to grab from some CAM";
        capL.release(); capR.release();
        return;
    }
    if ((imgL.size() != imgR.size()) || (imgL.type() != imgR.type()))  {
        cerr << "The cameras uses different framesize or type" << endl;
        capL.release(); capR.release();
        return;
    }
    // ENSURE RIGHT TYPE AND SIZE
    frameSize = imgL.size();
    // this will hold images from both cams 
    Mat frame(Size(2 * frameSize.width, frameSize.height), imgL.type());
    // define ROI to compose mosaic
    Mat frameL(frame(Rect(0, 0, frameSize.width, frameSize.height)));
    Mat frameR(frame(Rect(frameSize.width, 0, frameSize.width, frameSize.height)));
    // IN CASE YOU ...
(more)
edit flag offensive delete link more

Comments

Thank you very much, it works :)) My problem was, that I didn't specified CV_CAP_DSHOW flag

User gravatar imageUser ( 2016-04-23 07:36:51 -0600 )edit

But it works only for 320x240 resolution. Is it way to work for 640x480?

User gravatar imageUser ( 2016-04-23 09:27:01 -0600 )edit
  • Driver flag such as CV_CAP_DSHOW (or other driver) is optional. Default and available drivers depend on your OpenCV build
  • Not all CV_CAP_PROP_... are available nor work with all drivers. You should expect different result using different driver. For example on my PC I can't catch 30FPS using VFW while it works like a charm using DSHOW
  • About resolution... it works with all resolution supported by your cam. Set your frame size here: Size frameSize(yourWidth, yourHeight); . I suppose that delay between 2 cams might grows using bigger frame
pklab gravatar imagepklab ( 2016-04-23 11:55:17 -0600 )edit

Camera supports 640x480 resolution, but at that resolution only one of the cameras works. I. e. capL.read(imgR) gives true and capR.read(imgR) gives false

User gravatar imageUser ( 2016-04-23 13:09:06 -0600 )edit

@User see EDIT in my answer

pklab gravatar imagepklab ( 2016-04-28 03:14:19 -0600 )edit

@pklab Thank you for detailed explanaition and answer. But as I mentioned I try with 10 FPS even with 5, it says "unable grab from some Cam." because capR.read(imgR) gives false

User gravatar imageUser ( 2016-04-28 16:17:18 -0600 )edit

@User Sometimes 1st grab fails. Check the case with some loop like this

// GRAB ONCE TO GET FRAME INFO (we'll lost this frames)
// sometimes 1st grab fails so we'll retry 3 times
Mat imgL, imgR;
int cnt = 0;
while (imgL.empty() && (cnt < 4)) {
    capL >> imgL; cnt++;
}
cnt = 0;
while (imgR.empty() && (cnt < 4)) {
    capR >> imgR; cnt++;
}
if (imgL.empty() || imgR.empty()) {
    std::cerr << "Unable to grab from both cams";
    capL.release(); capR.release();
    return;
}
pklab gravatar imagepklab ( 2016-04-29 02:08:19 -0600 )edit

@pklab It doesn't work too :((( I was able to capture 640x480 at Linux with libv4l2cam library, but at Windows it doesn't work

User gravatar imageUser ( 2016-04-30 13:38:52 -0600 )edit

@User Maybe thread can helps. See this similar question

pklab gravatar imagepklab ( 2016-05-31 13:13:05 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-04-21 17:42:34 -0600

Seen: 2,958 times

Last updated: Apr 28 '16