簡體   English   中英

如何為Eigen :: EigenSolver使用Eigen :: Map對象?

[英]How can I use an Eigen::Map object for Eigen::EigenSolver?

我有一個連續的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

你不能用Map聲明一個EigenSolver ,矩陣類型必須是一個Matrix ,所以在你的情況下:

typedef Matrix<float,Dynamic,Dynamic,RowMajor> RowMatrixXf;
Map<RowMatrixXf> mMapped (m.ptr<float>(), m.rows, m.cols);
EigenSolver<MatrixXf> eig(mMapped);

您也可以使用RowMatrixXf實例化EigenSolver ,但性能應該更低,盡管有轉置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM