使用cv2eigen将cv :: Mat1f转换为Eigen :: MatrixXf时出错?

时间:2017-04-09 01:37:11

标签: c++ opencv eigen

我有这段代码:

#include "opencv2/core.hpp"
#include "opencv2/core/eigen.hpp"
#include <Eigen/Dense>


void CloudCache::DoPcaEigen(int dim){
    cv::Mat1f codes;
    ...
    Eigen::MatrixXf X = Eigen::MatrixXf(codes.rows,codes.cols);
    cv::cv2eigen(codes, X);
    ...
}

我使用-I/home/luca/eigen/

编译包括icpc

但是我收到了这个错误:

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(63): error #303: explicit type is missing ("int" assumed)
  void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src, Mat& dst )
                       ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(63): error: expected a ")"
  void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src, Mat& dst )
                            ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(81): error #303: explicit type is missing ("int" assumed)
  void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src,
                       ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(81): error: expected a ")"
  void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src,
                            ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(81): error: function template "cv::eigen2cv" has already been defined
  void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src,
       ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(96): error: identifier "Eigen" is undefined
                 Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst )
                 ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(96): error: Matrix is not a template
                 Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst )
                        ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(96): error: expected a ","
                 Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst )
                      ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(124): error: identifier "Eigen" is undefined
                 Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst )
                 ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(124): error: Matrix is not a template
                 Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst )
                        ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(124): error: expected a ","
                 Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst )
                      ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(142): error: identifier "Eigen" is undefined
                 Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst )
                 ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(142): error: Matrix is not a template
                 Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst )
                        ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(142): error: name followed by "::" must be a class or namespace name
                 Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst )
                                    ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(142): error: name followed by "::" must be a class or namespace name
                 Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst )
                                                    ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(142): error: expected a ","
                 Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst )
                      ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(170): error: identifier "Eigen" is undefined
                 Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst )
                 ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(170): error: Matrix is not a template
                 Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst )
                        ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(170): error: name followed by "::" must be a class or namespace name
                 Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst )
                                    ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(170): error: name followed by "::" must be a class or namespace name
                 Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst )
                                                    ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(170): error: expected a ","
                 Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst )
                      ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(189): error: identifier "Eigen" is undefined
                 Eigen::Matrix<_Tp, Eigen::Dynamic, 1>& dst )
                 ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(189): error: Matrix is not a template
                 Eigen::Matrix<_Tp, Eigen::Dynamic, 1>& dst )
                        ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(189): error: name followed by "::" must be a class or namespace name
                 Eigen::Matrix<_Tp, Eigen::Dynamic, 1>& dst )
                                    ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(189): error: expected a ","
                 Eigen::Matrix<_Tp, Eigen::Dynamic, 1>& dst )
                      ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(188): error: function template "cv::cv2eigen<_Tp>(const cv::Mat &, <error-type>, <error-type> &)" has already been defined
  void cv2eigen( const Mat& src,
       ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(214): error: identifier "Eigen" is undefined
                 Eigen::Matrix<_Tp, Eigen::Dynamic, 1>& dst )
                 ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(214): error: Matrix is not a template
                 Eigen::Matrix<_Tp, Eigen::Dynamic, 1>& dst )
                        ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(214): error: name followed by "::" must be a class or namespace name
                 Eigen::Matrix<_Tp, Eigen::Dynamic, 1>& dst )
                                    ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(214): error: expected a ","
                 Eigen::Matrix<_Tp, Eigen::Dynamic, 1>& dst )
                      ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(235): error: identifier "Eigen" is undefined
                 Eigen::Matrix<_Tp, 1, Eigen::Dynamic>& dst )
                 ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(235): error: Matrix is not a template
                 Eigen::Matrix<_Tp, 1, Eigen::Dynamic>& dst )
                        ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(235): error: name followed by "::" must be a class or namespace name
                 Eigen::Matrix<_Tp, 1, Eigen::Dynamic>& dst )
                                       ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(235): error: expected a ","
                 Eigen::Matrix<_Tp, 1, Eigen::Dynamic>& dst )
                      ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(234): error: function template "cv::cv2eigen<_Tp>(const cv::Mat &, <error-type>, <error-type> &)" has already been defined
  void cv2eigen( const Mat& src,
       ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(259): error: identifier "Eigen" is undefined
                 Eigen::Matrix<_Tp, 1, Eigen::Dynamic>& dst )
                 ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(259): error: Matrix is not a template
                 Eigen::Matrix<_Tp, 1, Eigen::Dynamic>& dst )
                        ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(259): error: name followed by "::" must be a class or namespace name
                 Eigen::Matrix<_Tp, 1, Eigen::Dynamic>& dst )
                                       ^

In file included from ../Core/CCCore.cpp(14):
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(259): error: expected a ","
                 Eigen::Matrix<_Tp, 1, Eigen::Dynamic>& dst )
                      ^

../Core/CCCore.cpp(244): error: no instance of overloaded function "cv::cv2eigen" matches the argument list
            argument types are: (cv::Mat1f, Eigen::MatrixXf)
        cv::cv2eigen(codes, X);
        ^
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(258): note: this candidate was rejected because mismatch in count of arguments
  void cv2eigen( const Matx<_Tp, 1, _cols>& src,
       ^
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(213): note: this candidate was rejected because mismatch in count of arguments
  void cv2eigen( const Matx<_Tp, _rows, 1>& src,
       ^
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(169): note: this candidate was rejected because mismatch in count of arguments
  void cv2eigen( const Matx<_Tp, _rows, _cols>& src,
       ^
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(141): note: this candidate was rejected because mismatch in count of arguments
  void cv2eigen( const Mat& src,
       ^
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(123): note: this candidate was rejected because mismatch in count of arguments
  void cv2eigen( const Matx<_Tp, _rows, _cols>& src,
       ^
/home/luca/ParallelOpenCV/install_icpc/include/opencv2/core/eigen.hpp(95): note: this candidate was rejected because mismatch in count of arguments
  void cv2eigen( const Mat& src,

为什么会这样?

1 个答案:

答案 0 :(得分:2)

似乎#include "opencv2/core/eigen.hpp"不包括Eigen本身,所以你需要

#include <Eigen/Core>
之前的那个。