9

I have trouble in using Eigen3 Library along with OpenCV application in C++. I have installed Eigen3 library on my Ubuntu using the following command:

sudo apt-get install libeigen3-dev

I am able to compile and use sample Eigen3 applications (Eigen3 library is installed and it works) when I use the following command to compile.

g++ -I/usr/include/eigen3 Eig.cpp -o Eig

I want to use the installed Eigen library with OpenCV.

I compiled OpenCV source with following flags:

cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=OFF -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON USE_EIGEN=/usr/include/eigen3 ..

My OpenCV code includes the following headers and namespace:

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <assert.h>
#include <opencv2/core/eigen.hpp>

using namespace cv;
using namespace std;
using namespace Eigen;

However, when I normally compile OpenCV application, my compiler gives me the following error:

In file included from Read.cpp:6:
/usr/local/include/opencv2/core/eigen.hpp:54: error: expected ‘,’ or ‘...’ before ‘::’ token
/usr/local/include/opencv2/core/eigen.hpp: In function ‘void cv::eigen2cv(int)’:
/usr/local/include/opencv2/core/eigen.hpp:56: error: ‘src’ was not declared in this scope
/usr/local/include/opencv2/core/eigen.hpp:56: error: ‘Eigen’ is not a class or namespace
/usr/local/include/opencv2/core/eigen.hpp:60: error: ‘dst’ was not declared in this scope
/usr/local/include/opencv2/core/eigen.hpp:66: error: ‘dst’ was not declared in this scope

How do I solve this problem?

garak
  • 4,713
  • 9
  • 39
  • 56
  • Did you forget the `-I/usr/include/eigen3` in your OpenCV application? – Emile Cormier Mar 26 '12 at 17:09
  • No. I'm compiling my OpenCV application with the following command: `g++ -I/usr/include/eigen3 -I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann -g Read.cpp -o Read` – garak Mar 26 '12 at 17:31

2 Answers2

11

I just had to include

#include <Eigen/Dense>

before including OpenCV headers thats all. I compiled them by including the Eigen lib headers and OpenCV lib headers.

garak
  • 4,713
  • 9
  • 39
  • 56
2

First i would double check that the eigen include directions are found. You can use a CMakeList.txt to do so (and you should use the cmake functions to find headers and link to libraries instead of compiler flags)

Next you could try to remove the using namespaces

    using namespace cv;
    using namespace std;
    using namespace Eigen;
  • I am able to see that the Eigen3 library headers are in place at /usr/include/eigen3 directory and I'm able to use them. Can you please elaborate on how to use a CMakeList.txt or direct me to a link? – garak Mar 26 '12 at 17:37