Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging cv::Mat horizontally

Tags:

c++

opencv

ubuntu

I want to merge a few cv::Mat, when I use mat1.push_back(mat2) it add mat2 to the end of mat1 vertically , is there a way to do this horizontally? The only other option I can think of is making every cv::Mat into a cv::RotatedRect, rotate it, creating a new Mat, merging, rotating everything in the end in the same way, but it sound pointlessly long if there is another way

like image 460
Tomer Avatar asked Nov 19 '13 18:11

Tomer


2 Answers

Take a look at hconcat and vconcat.

usage:

Mat M1,M2,HM,VM;
// M1 and M2 - source matrices
// HM,VM - results matrices
 ...

 hconcat(M1,M2,HM); // horizontal concatenation
 vconcat(M1,M2,VM); // vertical   concatenation

Take care, these methods are not documented.

like image 131
Andrey Smorodov Avatar answered Sep 18 '22 18:09

Andrey Smorodov


There is a very simple way of displaying two images side by side. The following function can be used which is provided by opencv.

Mat image1, image2;
hconcat(image1,image2,image1);//Syntax->
hconcat(source1,source2,destination);

This function can also be used to copy a set of columns from an image to another image.

Mat image;
Mat columns=image.colRange(20,30);
hconcat(image,columns,image);
like image 25
Raj Kumar Mishra Avatar answered Sep 21 '22 18:09

Raj Kumar Mishra