Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Eigen Library with OpenCV 2.3.1

Tags:

c++

opencv

eigen

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?

like image 928
garak Avatar asked Mar 26 '12 16:03

garak


2 Answers

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.

like image 96
garak Avatar answered Nov 03 '22 07:11

garak


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;
like image 2
Thorsten B'eggs Avatar answered Nov 03 '22 09:11

Thorsten B'eggs