PCA之后进行归一化
不过还是有问题,正在慢慢分析原因吧。
#include <cv.h> #include <cxcore.h> #include <highgui.h> #include <fstream> #include <iostream> #include <algorithm> using namespace std; int main() { ifstream myfile( "E:\\feature_size.txt "); if (!myfile.is_open()) cout << "Unable to open file"; int rows = 0,cols = 20; myfile >> rows ; //ifstream feature_file( "E:\\features.txt "); CvMat *fc = cvCreateMat(rows,cols,CV_32FC1); CvMat *dst = cvCreateMat(rows,cols,CV_32FC1); ifstream fin("E:\\feature_pca.txt ",std::ifstream::in); for(int i = 0;i < rows; ++i) for(int j = 0;j < cols; ++j) { fin >> fc->data.fl[i*cols+j]; } fin.close(); cvNormalize(fc,dst,1,0,CV_C,NULL); ofstream file( "E:\\feature_guiyihua.txt "); for (int i = 0; i < dst->rows;++i) { for(int j = 0;j < dst->cols; ++j) { file << cvmGet(dst,i,j) << " "; } file << "\n"; } }