Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

opencv display all Multi together in Single frame

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
}

opencv display all Multi video together in Single frame

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
}