OpenCV and PCL conflict?

别来无恙 提交于 2019-12-21 19:49:02

问题


I'm using OpenCV 2.4.2 and Point Cloud Library 1.6.0.

My program is working fine until I add the line...

#include <pcl/segmentation/segment_differences.h>

This causes errors when I try to compile. I get...

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'

So it looks like the Flann files that come with OpenCV are getting a conflict with the Flann files in PCL.

Any suggestions?

Edit

There is a similar question here PCL, OpenCV and flann conflict but it's a slightly different error...

Edit 2

so in my main.cpp file I previously had

using namespace pcl; using namespace cv;

I commented these two out and updated the program to use cv::Mat etc.

but I still get errors during compile when I add...

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


回答1:


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.




回答2:


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




回答3:


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_);


来源:https://stackoverflow.com/questions/12481208/opencv-and-pcl-conflict

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!