3

我正在使用 OpenCV 2.4.2 和点云库 1.6.0。

在我添加该行之前,我的程序运行良好...

#include <pcl/segmentation/segment_differences.h>

当我尝试编译时,这会导致错误。我得到...

Error   93  error C2872: 'flann' : ambiguous symbol C:\Program Files (x86)\PCL 1.6.0\include\pcl-1.6\pcl\kdtree\kdtree_flann.h  424
Error   94  error C2872: 'flann' : ambiguous symbol C:\Program Files (x86)\PCL 1.6.0\include\pcl-1.6\pcl\kdtree\kdtree_flann.h  425
Error   95  error C2872: 'flann' : ambiguous symbol C:\Program Files (x86)\PCL 1.6.0\include\pcl-1.6\pcl\kdtree\kdtree_flann.h  427
Error   96  error C2872: 'flann' : ambiguous symbol C:\Program Files (x86)\PCL 1.6.0\include\pcl-1.6\pcl\kdtree\kdtree_flann.h  514
Error   97  error C2872: 'flann' : ambiguous symbol C:\Program Files (x86)\PCL 1.6.0\include\pcl-1.6\pcl\kdtree\kdtree_flann.h  520

C:\Program Files (x86)\PCL 1.6.0\include\pcl-1.6\pcl/kdtree/kdtree_flann.h(520): error C2872: 'flann' : ambiguous symbol
              could be 'flann'
              or       'cv::flann'

所以看起来 OpenCV 附带的 Flann 文件与 PCL 中的 Flann 文件发生冲突。

有什么建议么?

编辑

这里有一个类似的问题 PCL, OpenCV and flann conflict 但这是一个略有不同的错误......

编辑 2

所以在我以前的 main.cpp 文件中

使用命名空间 pcl;使用命名空间简历;

我将这两个注释掉并更新了程序以使用 cv::Mat 等。

但是当我添加时我仍然在编译过程中遇到错误......

#include <pcl/segmentation/segment_differences.h>

C:\Program Files (x86)\PCL 1.6.0\include\pcl-1.6\pcl/kdtree/kdtree_flann.h(520): error C2872: 'flann' : ambiguous symbol 
          could be 'flann' 
          or       'cv::flann'

I've just tried renaming include\opencv2\flann\ to include\opencv2\flanncv\ and updating the includes in a bunch of opencv headers to this new flanncv directory. I'm still getting the above error...

4

3 回答 3

4

So a fix for this without having to rebuild things is to add a null namespace to it

change instances of flann::something to ::flann::something

I think it's effectivly telling it to use the global namespace and not the cv namespace.

于 2012-09-19T12:07:03.670 回答
0

Well I´m using pcl and openCv under linux but here goes

The problem is that both librarries are including the header file flann/flann.hpp or something similar, where the namespace flann is defined.

Now I don´t know how the libraries are installed on your machine, but I´ll assume that you used an insallable version of pcl and of openCv, so each one came with its own flann library.

Usually in the CMakeLists of both libraries there´s a line to search for the flann libraries, something like: INCLUDE_LIBRARY($(flann) REQUIRED)

a solution might be to remove the two installed libraries pcl and openCv. then download and install flann from their website. then download the nightly build of openCv and pcl, compile them and they should both be able to find the same instance of flann and so the problem might be solved

Edit: One more idea, maybe the problem is simply because you used in your code:

using namespace pcl;
using namespace cv;

and so you have 2 different instances from flann namespace. remove both "using namespace" and use instead in your code pcl::thepclclass, cv::theopencvclass and see if this helps

good luck

于 2012-09-18T17:01:20.167 回答
0

The solution simply is to add double colon like this (::) before flann Then everything will work well.

For example, it was:

flann::Matrix<ElementType>(new ElementType[size_*dim_], size_, dim_);

became:

::flann::Matrix<ElementType>(new ElementType[size_*dim_], size_, dim_);
于 2014-04-14T17:49:37.303 回答