Skip to content

Instantly share code, notes, and snippets.

@donaldmunro
Created February 24, 2017 16:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donaldmunro/beb7f226adf9c585c67f2599384e43ab to your computer and use it in GitHub Desktop.
Save donaldmunro/beb7f226adf9c585c67f2599384e43ab to your computer and use it in GitHub Desktop.
Map OpenCv Mat to Eigen Matrix and calculate Eigenvectors
#include <eigen3/Eigen/Dense>
#include <eigen3/Eigen/Eigenvalues>
..
..
using RowMatrixXf = Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
Eigen::Map<RowMatrixXf> mapped(extended_homograpy.ptr<float>(), homography.rows, homography.cols);
Eigen::EigenSolver<Eigen::MatrixXf> eigen_solve(mapped, true);
auto ev = eigen_solve.eigenvectors();
std::cout << "No of EigenVectors = " << ev.cols() << std::endl;
for (auto i=0; i<ev.cols(); i++)
{
std::cout << ev.col(i) << std::endl;
std::cout << "--------" << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment