Opencv float array to Mat


you can input float array data to Mat through this way.

float H[9]={1,2,3,4,5,6,7,8,9};
Mat TT = Mat(3,3,CV_32FC1, &H);

But becareful, if H value is changed, TT value is also changed.

See the example source code.



float H[9];
 for(int i=0; i< 9; ++i)
  H[i] = i;
 
 for(int i=0; i< 9; ++i)
  cout << i << " : " << H[i] << endl;

 Mat TT = Mat(3,3,CV_32FC1, &H);
 cout << TT << endl; 

 for(int i=0; i< 9; ++i)
  H[i] = i*10;

 cout << "TT values are chaned.." << endl;
 cout << TT << endl;

 cout << endl;
 
 
If we modify code like this..
 
Mat TT = Mat(3,3,CV_32FC1, &H);

-> Mat TT = Mat(3,3,CV_32FC1, &H).clone();

TT value is not affected by float array.


Comments

Popular posts from this blog

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

OpenCV Stitching example (Stitcher class, Panorama)

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.

Optical Flow sample source code using OpenCV

OpenCV Drawing Example, (line, circle, rectangle, ellipse, polyline, fillConvexPoly, putText, drawContours)

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

SICK LMS511 sensor data acquisition interface (source code, C++/MFC)

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

Image warping (using opencv findHomography, warpPerspective)