Use OpenCV for Virtual reality video with 2 cameras

asked 2020-05-13 05:11:28 -0600

marcusbarnet gravatar image

updated 2020-05-13 05:16:56 -0600

I have a very basic virtual reality helmet and two 4K USB cameras. I would like to be able to record a video with these two cameras by using Opencv in Ubuntu and C++ in order to playback it on my smartphone on the helmet.

I'm currently able to record and to stream images (in two different windows) coming from my two cameras in this way:

#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"

using namespace cv;
using namespace std;

    int main()
    {
        VideoCapture captureL("/dev/video0");
        if (!captureL.isOpened()) cout << "Problem on the left camera" << endl;
        VideoCapture captureR("/dev/video2");
        if (!captureR.isOpened()) cout << "Problem on the right camera" << endl;

        Mat imageL, imageR;

        while (1)
        {
            captureL >> imageL;
            captureR >> imageR;
            imshow("OriginalL", imageL);
            imshow("OriginalR", imageR);
            waitKey(1);
        }
    captureL.release();
    captureR.release();
    return 0;
    }

I would like to know if there is any document that I can study to understand how to implement the features I need. Is there any similar project or library which I can use as starting point?

The video format should be similar to the ones used for youtube videos, I took a screenshot as example.

image description

Thank you!

edit retag flag offensive close merge delete

Comments

1

It seems that you nee to use resize() and hconcat() functions...

kbarni gravatar imagekbarni ( 2020-05-13 12:22:37 -0600 )edit

Thank you @kbarni! So do you think I just have to use resize() to resize the window and hconcat() to merge the content of both cameras in the same window?

marcusbarnet gravatar imagemarcusbarnet ( 2020-05-16 13:34:38 -0600 )edit

resize() resizes the image, not the window. You might need it to get the square format instead of the 16:9 ratio (like your example image).

kbarni gravatar imagekbarni ( 2020-05-16 15:23:44 -0600 )edit