Ask Your Question
0

how can I use pca

asked 2014-12-05 13:11:02 -0600

DiQ gravatar image

updated 2017-12-30 15:00:41 -0600

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);
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-12-24 19:44:38 -0600

I don't really use OpenCV with C++, but it looks to me like surf_pca a matrix with only one row. surf_pca should have a number of rows equal to the total number of detected keypoint and each row should be a vector for a keypoint.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-12-05 13:11:02 -0600

Seen: 422 times

Last updated: Dec 08 '14