OpenCV Study, Merging to extended Mat from 2 Mat (example source code)

Example of merging to extended Mat from 2 Mat

For example,
A=[1 2 3; 4 5 6];
B=[7 8 9; 3 2 1];
C=[A; B];  < - how to make this merging Mat??

refer to this example source code.

---

Mat A(3, 10, CV_32F);
 Mat B(4, 10, CV_32F);

 int cnt=0;
 for(int i=0; i< A.rows; ++i)
 {
  for(int j=0; j< A.cols; ++j)
  {
   A.at< float>(i,j) = float(i*j);
  }
 }

 cout << "A" << endl;
 cout << A << endl << endl;
 
 for(int i=0; i< B.rows; ++i)
 {
  for(int j=0; j< B.cols; ++j)
  {
   B.at< float>(i,j) = float(i*j)*10;
  }
 }

 cout << "B" << endl;
 cout << B << endl << endl;
 


 Mat C(A.rows + B.rows, A.cols, CV_32F);
 memcpy(C.data, A.data, sizeof(float) * A.cols * A.rows );
 int startP = sizeof(float) * A.cols * A.rows;
 memcpy(&(C.data[ startP ]), B.data, sizeof(float) * B.cols * B.rows );

 cout << "C = [A; B]" << endl;
 cout << C << endl << endl;


...
The result of example source code..
 

Comments

Popular posts from this blog

OpenCV Stitching example (Stitcher class, Panorama)

(OpenCV Study) Background subtractor MOG, MOG2, GMG example source code (BackgroundSubtractorMOG, BackgroundSubtractorMOG2, BackgroundSubtractorGMG)

Example source code of extract HOG feature from images, save descriptor values to xml file, using opencv (using HOGDescriptor )

Real-time N camera stitching Class.

8 point algorithm (Matlab source code) / The method to get the Fundamental Matrix and the Essential matrix

Optical Flow sample source code using OpenCV

Video Stabilization example source code, (using cvFindHomography, cvWarpPerspective functions in openCV)

(OpenCV Study) calcOpticalFlowFarneback example source code ( dense optical flow )

yuv422(YUYV) to RGB and RGB to yuv422(YUYV), (Using OpenCV and TBB)

(C, C++) TinyXML , xml read & write