我有一个连续的OpenCV(非对称)矩阵cv::Mat m
,我想通过Eigen::EigenSolver
计算它的特征向量和特征值。
由于m
可能很大,因此通过cv2eigen
函数进行复制效率很低。然后,我想使用Eigen::Map
。这是我的代码:
Eigen::Map<Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>> mMapped (m.ptr<float>(), m.rows, m.cols);
Eigen::EigenSolver<Eigen::Map<Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>> solver(mMapped,true);//this gives a bunch of errors
最后一行给出了一堆错误(请参阅问题的结尾)。我怎么解决这个问题?请注意,我应该避免将mMapped
复制到矩阵对象,否则它等同于使用cv2eigen
(我认为)。
/usr/local/include/eigen3/Eigen/src/Eigenvalues/EigenSolver.h: In instantiation of ‘class Eigen::EigenSolver<Eigen::Map<Eigen::Matrix<float, -1, -1, 1> > >’:
../Math.hpp:64:104: required from ‘static void Math::createHashTable(const cv::Mat&, cv::Mat&, cv::Mat&, int, int) [with T = float]’
../CloudCache.cpp:155:58: required from here
/usr/local/include/eigen3/Eigen/src/Eigenvalues/EigenSolver.h:71:10: error: ‘Options’ is not a member of ‘Eigen::EigenSolver<Eigen::Map<Eigen::Matrix<float, -1, -1, 1> > >::MatrixType {aka Eigen::Map<Eigen::Matrix<float, -1, -1, 1> >}’
enum {
^
In file included from /usr/local/include/eigen3/Eigen/Eigenvalues:29:0,
from ../Math.hpp:16,
from ../CloudCache.cpp:15:
/usr/local/include/eigen3/Eigen/src/Eigenvalues/RealSchur.h: In instantiation of ‘class Eigen::RealSchur<Eigen::Map<Eigen::Matrix<float, -1, -1, 1> > >’:
/usr/local/include/eigen3/Eigen/src/Eigenvalues/EigenSolver.h:312:27: required from ‘class Eigen::EigenSolver<Eigen::Map<Eigen::Matrix<float, -1, -1, 1> > >’
../Math.hpp:64:104: required from ‘static void Math::createHashTable(const cv::Mat&, cv::Mat&, cv::Mat&, int, int) [with T = float]’
../CloudCache.cpp:155:58: required from here
/usr/local/include/eigen3/Eigen/src/Eigenvalues/RealSchur.h:58:10: error: ‘Options’ is not a member of ‘Eigen::RealSchur<Eigen::Map<Eigen::Matrix<float, -1, -1, 1> > >::MatrixType {aka Eigen::Map<Eigen::Matrix<float, -1, -1, 1> >}’
enum {
^
In file included from /usr/local/include/eigen3/Eigen/src/Eigenvalues/RealSchur.h:14:0,
from /usr/local/include/eigen3/Eigen/Eigenvalues:29,
from ../Math.hpp:16,
from ../CloudCache.cpp:15:
/usr/local/include/eigen3/Eigen/src/Eigenvalues/HessenbergDecomposition.h: In instantiation of ‘class Eigen::HessenbergDecomposition<Eigen::Map<Eigen::Matrix<float, -1, -1, 1> > >’:
/usr/local/include/eigen3/Eigen/src/Eigenvalues/RealSchur.h:228:41: required from ‘class Eigen::RealSchur<Eigen::Map<Eigen::Matrix<float, -1, -1, 1> > >’
/usr/local/include/eigen3/Eigen/src/Eigenvalues/EigenSolver.h:312:27: required from ‘class Eigen::EigenSolver<Eigen::Map<Eigen::Matrix<float, -1, -1, 1> > >’
../Math.hpp:64:104: required from ‘static void Math::createHashTable(const cv::Mat&, cv::Mat&, cv::Mat&, int, int) [with T = float]’
../CloudCache.cpp:155:58: required from here
/usr/local/include/eigen3/Eigen/src/Eigenvalues/HessenbergDecomposition.h:64:10: error: ‘Options’ is not a member of ‘Eigen::HessenbergDecomposition<Eigen::Map<Eigen::Matrix<float, -1, -1, 1> > >::MatrixType {aka Eigen::Map<Eigen::Matrix<float, -1, -1, 1> >}’
enum {
^
subdir.mk:30: recipe for target 'CloudCache.o' failed
make: *** [CloudCache.o] Error 1
答案 0 :(得分:1)
您无法使用EigenSolver
声明Map
,矩阵类型必须为Matrix
,因此在您的情况下:
typedef Matrix<float,Dynamic,Dynamic,RowMajor> RowMatrixXf;
Map<RowMatrixXf> mMapped (m.ptr<float>(), m.rows, m.cols);
EigenSolver<MatrixXf> eig(mMapped);
您也可以使用EigenSolver
实例化RowMatrixXf
,但性能应该更低,尽管有换位。