Minoru 3d: How to reduce delay between left and right frames?

asked 2017-05-19 00:22:09 -0500

shome gravatar image

I am using the following code(from simulataneous_minoru3d_opencv_forums) to access video from minoru 3d webcam. However there is observable lag between left and right frame. I have tried increasing frame rate, reducing image size but all are failing. How can I reduce the time lag between the frames? It should be possible as i ahave seen youtube videos captured by minoru which dont seem to have any lag.

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;

void Main_GrabFrom2CamWriteMosaic()
{
// SELECT CAM ID FOR YOUR CAMS
int camL = 0, camR = 1;

VideoCapture capL(camL);
VideoCapture capR(camR);

//SET SAME SETTINGS ON BOTH CAM
Size frameSize(320, 240);
double fps = 30;

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;
}

// 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 WANT TO SAVE A VIDEO
bool isColor = imgL.type() == CV_8UC3;
CV_Assert(isColor);
double fourcc;

// THE GRAB LOOP
for (;;)
{
    // GRAB THE NEXT FRAME FROM VIDEO CAMERA
    if (! (capL.grab() && capR.grab()) ) {
        std::cerr << "Unable to grab from one or both cameras"; 
        break;
    }
    // ENCODE AND RETURN THE JUST GRABBED FRAME
    // you can't grab into a ROI
    capL.retrieve(imgL);
    capR.retrieve(imgR);
    if (imgL.empty() || imgR.empty()) {
        std::cerr << "Empty frame received from some CAM !";
        break;
    }
    // COMPOSE MOSAIC show and save
    imgL.copyTo(frameL);
    imgR.copyTo(frameR);
    cv::imshow("frame", frame);
    if (cv::waitKey(30) >= 0) break;
}
capL.release();
capR.release();

}

int main() {

Main_GrabFrom2CamWriteMosaic();

return 0;
}
edit retag flag offensive close merge delete