Created
June 2, 2015 09:51
-
-
Save ashwin/c62d0d25fb63c142be92 to your computer and use it in GitHub Desktop.
Eigen vectors and eigen values in OpenCV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <opencv/cv.h> | |
| // Input mat: 100 6-dimensional points | |
| // Rows: 100 Cols: 6 Type: CV_F32 | |
| cv::Mat pt_mat; | |
| cv::PCA pt_pca(pt_mat, cv::Mat(), CV_PCA_DATA_AS_ROW, 0); | |
| // Mean | |
| // Rows: 1 Cols: 6 | |
| cv::Mat pt_mean = pt_pca.mean; | |
| // Eigen values | |
| // In highest to lowest order | |
| // Rows: 6 Cols: 1 | |
| cv::Mat pt_eig_vals = pt_pca.eigenvalues; | |
| for (int i = 0; i < 6; ++i) | |
| std::cout << pt_eig_vals.at<float>(i, 0) << std::endl; | |
| // Eigen vectors | |
| cv::Mat pt_eig_vecs = pt_pca.eigenvectors; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment