Video from 2 cameras (for Stereo Vision) using OpenCV, but one of them is behind

I am trying to create a Stereo Vision using 2 Logitech C310 webcams. But the result is not good enough. One of the videos is behind the other.

Here is my openCV program using VC ++ 2010:

#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <iostream>

using namespace cv;
using namespace std;

int main()
{
    try
    {
        VideoCapture cap1;
        VideoCapture cap2;

        cap1.open(0);
        cap1.set(CV_CAP_PROP_FRAME_WIDTH, 1040.0);
        cap1.set(CV_CAP_PROP_FRAME_HEIGHT, 920.0);

        cap2.open(1);  
        cap2.set(CV_CAP_PROP_FRAME_WIDTH, 1040.0);
        cap2.set(CV_CAP_PROP_FRAME_HEIGHT, 920.0);
        Mat frame,frame1;

        for (;;)
        {
            Mat frame;
            cap1 >> frame;

            Mat frame1;
            cap2 >> frame1;

            transpose(frame, frame);
            flip(frame, frame, 1);

            transpose(frame1, frame1);
            flip(frame1, frame1, 1);

            imshow("Img1", frame);
            imshow("Img2", frame1);

            if (waitKey(1) == 'q')
                break;
        }

        cap1.release();
        return 0;
    }
    catch (cv::Exception & e)
    {
        cout << e.what() << endl;
    }
}

How can I avoid lag?

+4
source share
3 answers

you are probably saturating the USB bus.

try connecting one in front and the other in the back (hoping to land on different buses),

or reduce frame size / FPS to generate less traffic.

+2
source

, . Opencv Videocapture , .

, - , API , .

- USB , - , , .

+1

, , , ...

, USB-. , . , VideoCapture , , : VideoCapture cap1, cap1 , VideoCapture cap2, cap2 THEN cap1 cap2, , cap1, , , cap2, ... .

What if you really want to use opencv for this - add some streams: one deals with the left frames and the other with the correct frames, and does nothing but save the last frame received (so that you will always deal with the latest frames). If you want to get your frames, you just need to get them from abstract threads.

I have done something if you need here .

0
source

Source: https://habr.com/ru/post/1525534/


All Articles