Consider two matrices as input parameters of the following sample_method()
method, I want to merge the two matrices m1
and m2
in a new matrix m12
. I read this reference and then also this reference, but these two solutions copy the data from source matrices to the destination matrix.
bool sample_method(const Mat& m1, const Mat& m2)
{
if(m1.cols != m2.cols)
{
cout << "Error: m1.cols != m2.cols" << endl;
return false;
}
Mat m12(m1.rows+m2.rows,m1.cols,DataType<float>::type);
// merging m1 and m2
m12(Rect(0,0,m1.cols,m1.rows)) = m1;
m12(Rect(0,m1.rows,m2.cols,m2.rows)) = m2;
return true;
}
How could I concatenate two Mat in a single Mat without copying the data? Why my code does not work?