Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version


Hi, I am trying to reduce the dimensionality of my feature set using PCA and then classification using SVM.

I have created and populated my feature matrix and label matrix :

  Mat labels(875, 1, CV_32F);

  Mat trainingData(875, 23040, CV_32F);

Where each row corresponds to an image and each column is a feature. The features are histogram bins (256) from multiple regions in the image (90 regions). 90x256 = 23040.

I now want to reduce the 23040 features to something less before training, say 512 features. I have this:

/*Reduce dimensionality using PCA*/

Mat projection_result;

PCA pca(trainingData, Mat(), CV_PCA_DATA_AS_ROW,512);

pca.project(trainingData, projection_result);


CvSVMParams params;
params.svm_type = CvSVM::C_SVC;
params.kernel_type = CvSVM::RBF;

SVM.train_auto(projection_result, labels, Mat(), Mat(), params);"trainedData_test.xml");

My question is, is this correct ? And how would I now use prediction with PCA ?

/*Load SVM*/


/*Populate test matrix*/

  Mat testData(1, 23040, CV_32F);

/*PCA ???*/


int label = SVM.predict(projection_result ???);

Thanks !