I have 4 frames I would like to put all them in one window..
I am following this tutorial which should be perfect for my objective .. but my code is not working..
This is the code I am working on (resumed)
VideoCapture capture;
Mat currentFrame;
Mat foreground;
Mat postfgmask;
Mat resultframe;
Size imgFixedSize = Size(500, 350);
Mat roi;
Mat merged = Mat(Size(imgFixedSize*height*2, imgFixedSize*width*2), CV_8UC3);
/* initialize capture and read frame, not shown .. */
capture >> currentFrame;
resize(currentFrame, currentFrame, imgFixedSize);
/*
image processing tasks, not shown ..
all frames are Size(500, 350) ..
*/
roi = Mat(merged, Rect(0, 0, 500, 350));
currentFrame.copyTo(roi);
roi = Mat(merged, Rect(500, 0, 500, 350));
foreground.copyTo(roi);
roi = Mat(merged, Rect(0, 350, 500, 350));
postfgmask.copyTo(roi);
roi = Mat(merged, Rect(500, 350, 500, 350));
resultframe.copyTo(roi);
imshow("Output", merged);
writer.write(merged);
But when I execute the program, it crashes giving this errror to the output:
OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in Mat, file /home/user/opencv/modules/core/src/matrix.cpp, line 522
terminate called after throwing an instance of 'cv::Exception'
what(): /home/user/opencv/modules/core/src/matrix.cpp:522: error: (-215) 0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows in function Mat
Aborted
It seems that the error is due to frames size .. But the dimensions are quiet clear and the output window is doubled in size so it can fit 4 frames..
So how do I have to change my code to make it works ?