Search code examples
c++opencveigen

Error converting cv::Mat1f to Eigen::MatrixXf with cv2eigen?


I have this code:

#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);
    ...
}

And I compile it including -I/home/luca/eigen/ with icpc

But I get this error:

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,

Why this happens?


Solution

  • It seems that #include "opencv2/core/eigen.hpp" does not include Eigen itself, so you need to

    #include <Eigen/Core>
    

    before that.