Apply function to all Eigen matrix element

Yes, use the Eigen::MatrixBase<>::unaryExpr() member function. Example: #include <cmath> #include <iostream> #include <Eigen/Core> double Exp(double x) // the functor we want to apply { return std::exp(x); } int main() { Eigen::MatrixXd m(2, 2); m << 0, 1, 2, 3; std::cout << m << std::endl << “becomes: “; std::cout << std::endl << m.unaryExpr(&Exp) << std::endl; }

Convert Eigen Matrix to C array

You can use the data() member function of the Eigen Matrix class. The layout by default is column-major, not row-major as a multidimensional C array (the layout can be chosen when creating a Matrix object). For sparse matrices the preceding sentence obviously doesn’t apply. Example: ArrayXf v = ArrayXf::LinSpaced(11, 0.f, 10.f); // vc is the … Read more

Initialise Eigen::vector with std::vector

According to Eigen Doc, Vector is a typedef for Matrix, and the Matrix has a constructor with the following signature: Matrix (const Scalar *data) Constructs a fixed-sized matrix initialized with coefficients starting at data. And vector reference defines the std::vector::data as: std::vector::data T* data(); const T* data() const; Returns pointer to the underlying array serving … Read more

Eigen and std::vector

Eigen uses contiguous memory, as does std::vector. However, the outer std::vector contains a contiguous set of std::vector<std::complex<double> >, each pointing to a different set of complex numbers (and can be different lengths). Therefore, the std “matrix” is not contiguous. What you can do is copy the data to the Eigen matrix, there are multiple ways … Read more

OpenCV CV::Mat and Eigen::Matrix

You can also use void eigen2cv(const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src, Mat& dst) and void cv2eigen(const Mat& src, Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst) from #include <opencv2/core/eigen.hpp>.

Find package Eigen3 for CMake

Since Eigen3 is completely header only, all you ever need is the path to the include directory. And this one, you are already defining manually anyway. So there is no real need for a FindEigen3.cmake or FIND_PACKAGE call. Simply use INCLUDE_DIRECTORIES ( “$ENV{EIGEN3_INCLUDE_DIR}” ) or SET( EIGEN3_INCLUDE_DIR “$ENV{EIGEN3_INCLUDE_DIR}” ) IF( NOT EIGEN3_INCLUDE_DIR ) MESSAGE( FATAL_ERROR … Read more