How to dewarp the videos in 360 deg view

asked 2017-07-20 12:25:26 -0500

indra gravatar image

Hi, I have video from 4 different camera I want to dewarp the, in 360 degree view or stitch the 4 videos in to single view ?

I have written the below code to display the 4 videos but could not get how to dewarp them

int main(int argc, char** argv)

//string firstvideo = "1.avi";

string firstvideo = "1.avi";
string secondvideo= "2.avi";

string thirddvideo = "3.avi";

string fourthvideo = "4.avi";

VideoCapture capture(firstvideo);
//VideoCapture capture(0); /* if we need to read from the Direct Camera*/
VideoCapture capture1(secondvideo);
VideoCapture capture2(thirddvideo);
VideoCapture capture3(fourthvideo);

Mat frame;
Mat frame1;
Mat frame2;
Mat frame3;

if( !capture.isOpened() )
    throw "Error when reading steam_avi0";
if( !capture1.isOpened() )
    throw "Error when reading steam_avi1";
if( !capture2.isOpened() )
    throw "Error when reading steam_avi2";
if( !capture3.isOpened() )
    throw "Error when reading steam_avi3";

namedWindow( "w", 1);

for( ; ; )
    capture >> frame;
    capture1 >> frame1;

    capture2 >> frame2;
    capture3 >> frame3;

    resize(frame, frame, Size(640, 360), 0, 0, INTER_CUBIC);
    resize(frame1, frame1, Size(640, 360), 0, 0, INTER_CUBIC);
    resize(frame2, frame2, Size(640, 360), 0, 0, INTER_CUBIC);
    resize(frame3, frame3, Size(640, 360), 0, 0, INTER_CUBIC);

    Mat canvas = Mat::zeros(frame.rows*4+1, frame.cols*4+1, frame.type());

    frame.copyTo(canvas(Rect(0,0,frame.cols,frame.rows )));
    frame1.copyTo(canvas(Rect(frame.cols,0,frame1.cols,frame1.rows )));
    frame2.copyTo(canvas(Rect(0,frame.rows,frame2.cols,frame2.rows )));
    frame3.copyTo(canvas(Rect(frame2.cols,frame1.rows,frame3.cols,frame3.rows )));
    // if it is too big to fit on the screen, then scale it down by 2, hopefully it'll fit :-)

    imshow("w", canvas);
waitKey(0); // key press to close window
// releases and window destroy are automatic in C++ interface
edit retag flag offensive close merge delete


do your videos overlap ? (then try opencv's stitching module) else you can do your own equirectangular projection using remap() (should be fast enough for realtime even)

berak gravatar imageberak ( 2017-07-21 22:16:39 -0500 )edit

Hi, yes out of 4 two gets overlap , the above example you mentioned is for image ,, I need some example which works for videos so that I can try and build on top that ....

thanks ....

indra gravatar imageindra ( 2017-07-23 08:10:09 -0500 )edit