Merge multiple cv::Mat?

dynamic picture dynamic · Jun 24, 2012 · Viewed 8k times · Source

Basically I have 3 mat like this:

Mat descriptors1
Mat descriptors2
Mat descriptors3

Where each descriptors have been loaded like this:

extractor->compute( object, kp, descriptors );

How could I join in a single Mat all the descriptors (append one mat to the other) ?

Example:

Mat fullDesc = descriptors1 + descriptors2 + descriptors3;

Answer

Andrey Kamaev picture Andrey Kamaev · Jun 24, 2012

Not very effective, but short:

descriptors1.push_back(descriptors2);
descriptors1.push_back(descriptors3);

After that descriptors1 will be a concatenation.


Also there is an undocumented function vconcat:

void vconcat(const Mat* src, size_t nsrc, OutputArray dst);
void vconcat(InputArray src1, InputArray src2, OutputArray dst);
void vconcat(InputArrayOfArrays src, OutputArray dst);