#define DIMENTIONS 7
#define SAMPLE_NUM 5
float Coordinates[DIMENTIONS*SAMPLE_NUM]={
101.5,100.4,97.0,98.7,100.8,114.2,104.2
,100.8,93.5,95.9,100.7,106.7,104.3,106.4
,100.8,97.4,98.2,98.2,99.5,103.6,102.4
,99.4,96.0,98.2,97.8,99.1,98.3,104.3
,101.8,97.7,99.0,98.1,98.4,102.0,103.7
};
int main()
{
Mat pcaSet(SAMPLE_NUM, DIMENTIONS, CV_32FC1);
for (int i=0; i<(SAMPLE_NUM); ++i)
{
for (int j=0; j<DIMENTIONS; ++j)
{
pcaSet.at<float>(i, j) = Coordinates[i*DIMENTIONS + j];
}
}
//PCA pca(pcaSet, Mat(), CV_PCA_DATA_AS_ROW);///
PCA *pca = new PCA(pcaSet, Mat(), CV_PCA_DATA_AS_ROW);///
cout << "eigenvalues:" <<endl << pca->eigenvalues <<endl<<endl;
cout << "eigenvectors" <<endl << pca->eigenvectors << endl;
delete pca;
return 0;
}
PCA-主成分分析
最新推荐文章于 2024-07-10 21:47:50 发布