Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Ok, shouldnt be that hard. I assume that all have the same height (otherwise find the biggest height) The 3 input images are img1, img2, img3.

cv::Size s1 = img1.size();
cv::Size s2 = img2.size();
cv::Size s3 = img3.size();

cv::Mat output(s1.height, s1.width + s2.width + s3.width, CV_MAT_TYPE); // put in the type of your mat

cv::Mat help1(output, cv::Rect(0,0, s1.width, s1.height);
cv::Mat help2(output, cv::Rect(s1.width, 0, s2.width, s2.height);
cv::Mat help3(output, cv::Rect(s1.width + s2.width, 0, s3.width, s3.height);

img1.copyTo(help1);
img2.copyTo(help2);
img3.copyTo(help3);

cv::imshow("Output", output);

Here is how this works: You create an output image that has the total size of all 3 images. Then you create 3 Mats that only point to a part of your output image that equals their respective input image. This only works since Mat(output, Rect()) does not copy the output Mat to a new one, it only points to it. So by img.copyTo(help) you copy the input image to the respective part in output.