Void cvFitPlane (const CvMat * points, float * plane) {
//Estimate geometric centroid.
Int nrows=points - & gt; Rows;
Int ncols=points - & gt; Cols.
The int type=points - & gt; The type;
CvMat * centroid=cvCreateMat (1, ncols, type);
CvSet (centroid, cvScalar (0));
For (int c=0; C
{
Centroid - & gt; Data. Fl [c] +=points - & gt; Data. The fl (ncols * r + c),
}
Centroid - & gt; Data. Fl. [c]/=nrows;
}
//Subtract geometric centroid from each point.
CvMat * points2=cvCreateMat (nrows, ncols, type);
For (int r=0; R
//the Evaluate SVD of covariance matrix.
A=CvMat * cvCreateMat (ncols, ncols, type);
CvMat * W=cvCreateMat (ncols, ncols, type);
CvMat * V=cvCreateMat (ncols, ncols, type);
CvGEMM (points2, points, 1, NULL, 0, A, CV_GEMM_A_T);
CvSVD (A, W, NULL, V, CV_SVD_V_T);
//Assign parts relate coefficients by the singular vector corresponding to the smallest singular value.
Plane/ncols=0;
For (int c=0; C
Plane [ncols] +=plane [c] * centroid - & gt; Data. Fl. [c];
}
//Release allocated resources.
CvReleaseMat (¢roid);
CvReleaseMat (& amp; Points2);
CvReleaseMat (& amp; A);
CvReleaseMat (& amp; W);
CvReleaseMat (& amp; V);
}
Call way:
(CPP) view plain copy
CvMat * points_mat=cvCreateMat (X_vector. The size (), 3, CV_32FC1);//definition is used to store need fitting point matrix
for (int i=0; I & lt; X_vector. The size (); + + I)
{
Points_mat - & gt; Data. The fl [I * 3 + 0]=X_vector [I];//matrix initialized values of X coordinate values of the
Points_mat - & gt; Data. The fl * 3 + 1 [I]=Y_vector [I];//Y coordinate values
Points_mat - & gt; Data. The fl [I * 3 + 2]=Z_vector [I]; //Z coordinate values & lt;/span>
}
Float plane12 [4]={0};//definition is used to store plane parameters array
CvFitPlane (points_mat plane12);//call equation
We are fitting out of the equation: Ax + By + Cz=D
In which A=plane12 [0], B=plane12 [1], C=plane12 [2], D=plane12 [3],
See this fitting plane program on the Internet, X_vector is not very good. The size (), X_vector [I], Y_vector [I], Z_vector [I] the meaning of these three parameters, is to get the x, y, z coordinates respectively in the three matrices? The data. The fl [] is what mean? O great god answer if there are other algorithm also thank you very much
CodePudding user response:
Should be put in, the data is generalCodePudding user response:
The data is a X_vector. Size line 3 columns of the matrix is?CodePudding user response: