8

我在C++中使用Eigen3 Library 和OpenCV应用程序时遇到了麻烦。我已经使用以下命令在我的 Ubuntu 上安装了 Eigen3 库:

sudo apt-get install libeigen3-dev

当我使用以下命令进行编译时,我能够编译和使用示例 Eigen3 应用程序(安装了 Eigen3 库并且它可以工作)。

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

我想将已安装的 Eigen 库与 OpenCV 一起使用。

我用以下标志编译了 OpenCV 源代码:

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 ..

我的 OpenCV 代码包括以下标头和命名空间:

#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;

但是,当我通常编译 OpenCV 应用程序时,我的编译器给了我以下错误:

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

我该如何解决这个问题?

4

2 回答 2

10

我只需要包括

#include <Eigen/Dense>

在包括 OpenCV 标头之前就是这样。我通过包含 Eigen 库头文件和 OpenCV 库头文件来编译它们。

于 2012-03-28T15:14:54.210 回答
2

首先,我会仔细检查是否找到了特征包含方向。您可以使用 CMakeList.txt 来执行此操作(并且您应该使用 cmake 函数来查找标头并链接到库而不是编译器标志)

接下来,您可以尝试删除 using 命名空间

    using namespace cv;
    using namespace std;
    using namespace Eigen;
于 2012-03-26T17:20:56.163 回答