将特征库与OpenCV 2.3.1

Using Eigen Library with OpenCV 2.3.1

本文关键字:OpenCV 特征      更新时间:2023-10-16

我在C++中使用Eigen3库和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

我该如何解决这个问题?

我只需要包括

#include <Eigen/Dense>

在包括OpenCV标题之前,仅此而已。我通过包含Eigen lib标头和OpenCV lib标头来编译它们。

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

接下来,您可以尝试删除使用名称空间

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