Ask Your Question
0

opencv display all Multi video together in Single frame

asked 2017-06-10 14:32:20 -0600

indra gravatar image

updated 2017-06-10 14:35:13 -0600

I am writing a openCV simple program to display multivideo in single frame.

I could write for two video , I want for 4 videos, Could some body guide how to display 4 videos in single frame (Like 4 videos in Square kind of frame. below is my code

 int main(int argc, char** argv)
{
   string filename = "/home/user/testaviravi.avi";
   VideoCapture capture(filename);
   VideoCapture capture1(filename);

   Mat frame;
   Mat frame1;

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

  namedWindow( "w", 1);

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

    if(frame.empty())
         break;

    if(frame1.empty())
        break;

    Mat canvas = Mat::zeros(frame.rows*2+1, frame.cols*2+1, frame.type());
    frame.copyTo(canvas(Range::all(), Range(0, frame.cols)));
    frame1.copyTo(canvas(Range::all(), Range(frame1.cols+1, frame1.cols*2+1)));
    // 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

Comments

I don't think use " for( ; ; )" to get image from 2 or even 4 cameras is a good idea.

jsxyhelu gravatar imagejsxyhelu ( 2017-06-11 10:34:49 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-06-10 15:21:34 -0600

LBerger gravatar image

try with

capture >> frame;
capture1 >> frame1;
capture2 >> frame2;
capture3 >> frame3;

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 )));
edit flag offensive delete link more

Comments

Hi, Thanks it worked .. Is it possible to dewarp these 4 videos in 360 degree view using openCV? if its possible Could you guide how to do it?

indra gravatar imageindra ( 2017-06-18 12:50:49 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-06-10 14:32:20 -0600

Seen: 179 times

Last updated: Jun 10 '17