Ask Your Question

DiQ's profile - activity

2014-12-08 04:08:38 -0600 received badge  Editor (source)
2014-12-05 13:11:02 -0600 asked a question how can I use pca

I'm using PCA algorithm to reduce the dimensionality of my surf descriptor. For this purpose, Firstly, I calculate surf points and put all values of the matrix as one row with too many columns as rows (points detected) multiplied by cols (64, in case of SURF descriptor) the descriptor has. That works perfectly. But, when I project in the PCA subspace, the result is a matrix (compressed) with 0 data. My question is: Am I implementing the algorithm well? Is it possible what I'm trying to do?

code:

//Calculate surf points
surf.detect(GRAY,keypoints,masc_gray);
surf.compute(GRAY,keypoints,descriptor_surf);

//Prepare descriptor to pass as PCA input (1 row per image)
Mat surf_pca(1,descriptor_surf.rows*descriptor_surf.cols,CV_32FC1);
desc_s.reshape(1,1).row(0).convertTo(surf_pca,CV_32FC1);

int maxcomp = 128;
PCA pca(surf_pca,Mat(),CV_PCA_DATA_AS_ROW,maxcomp);
Mat compressed (surf_pca.rows, maxcomp, CV_32FC1);
compressed = pca.project(surf_pca);