ROS-Kinect 自带opencv与自定义的opencv版本兼容问题

最近在ros上建立opencv工程,总有些包不能如愿加入,编译失败,在windows下用的GpuMat在ros下也不能通过:

最开始报错:

报错:[ 14%] Built target segnet_lib
[ 21%] Building CXX object pa_stitching/CMakeFiles/pa_stitching_node.dir/src/main.cpp.o
[ 78%] Built target densecrf
[ 92%] Built target stitching_node
In file included from /home/wds/catkin_ws/src/pa_stitching/include/Configure.h:12:0,
                 from /home/wds/catkin_ws/src/pa_stitching/src/main.cpp:2:
/usr/local/include/opencv2/gpu/gpu.hpp:432:29: error: ‘vector’ does not name a type
 CV_EXPORTS void merge(const vector<GpuMat>& src, GpuMat& dst, Stream& stream = 
                             ^
/usr/local/include/opencv2/gpu/gpu.hpp:432:35: error: expected ‘,’ or ‘...’ before ‘<’ token
 CV_EXPORTS void merge(const vector<GpuMat>& src, GpuMat& dst, Stream& stream = 
                                   ^
/usr/local/include/opencv2/gpu/gpu.hpp:438:42: error: ‘vector’ has not been declared
 CV_EXPORTS void split(const GpuMat& src, vector<GpuMat>& dst, Stream& stream = 
                                          ^
/usr/local/include/opencv2/gpu/gpu.hpp:438:48: error: expected ‘,’ or ‘...’ before ‘<’ token
 CV_EXPORTS void split(const GpuMat& src, vector<GpuMat>& dst, Stream& stream = 
                                                ^
/usr/local/include/opencv2/gpu/gpu.hpp:1265:4: error: ‘vector’ does not name a type
    vector<Point> locations;
    ^
/usr/local/include/opencv2/gpu/gpu.hpp:1266:4: error: ‘vector’ does not name a type
    vector<double> confidences;
    ^
/usr/local/include/opencv2/gpu/gpu.hpp:1267:4: error: ‘vector’ does not name a type
    vector<double> part_scores[4];
    ^
/usr/local/include/opencv2/gpu/gpu.hpp:1285:31: error: ‘vector’ does not name a type
     void setSVMDetector(const vector<float>& detector);
                               ^
/usr/local/include/opencv2/gpu/gpu.hpp:1285:37: error: expected ‘,’ or ‘...’ before ‘<’ token
     void setSVMDetector(const vector<float>& detector);
                                     ^
/usr/local/include/opencv2/gpu/gpu.hpp:1287:12: error: ‘vector’ does not name a type
     static vector<float> getDefaultPeopleDetector();
            ^
/usr/local/include/opencv2/gpu/gpu.hpp:1288:12: error: ‘vector’ does not name a type
     static vector<float> getPeopleDetector48x96();
            ^
/usr/local/include/opencv2/gpu/gpu.hpp:1289:12: error: ‘vector’ does not name a type
     static vector<float> getPeopleDetector64x128();
            ^
/usr/local/include/opencv2/gpu/gpu.hpp:1291:36: error: ‘vector’ has not been declared
     void detect(const GpuMat& img, vector<Point>& found_locations,
                                    ^
/usr/local/include/opencv2/gpu/gpu.hpp:1291:42: error: expected ‘,’ or ‘...’ before ‘<’ token
     void detect(const GpuMat& img, vector<Point>& found_locations,
                                          ^
/usr/local/include/opencv2/gpu/gpu.hpp:1295:46: error: ‘vector’ has not been declared
     void detectMultiScale(const GpuMat& img, vector<Rect>& found_locations,
                                              ^
/usr/local/include/opencv2/gpu/gpu.hpp:1295:52: error: expected ‘,’ or ‘...’ before ‘<’ token
     void detectMultiScale(const GpuMat& img, vector<Rect>& found_locations,
                                                    ^
/usr/local/include/opencv2/gpu/gpu.hpp:1300:47: error: ‘vector’ has not been declared
     void computeConfidence(const GpuMat& img, vector<Point>& hits, double hit_t
                                               ^
/usr/local/include/opencv2/gpu/gpu.hpp:1300:53: error: expected ‘,’ or ‘...’ before ‘<’ token
     void computeConfidence(const GpuMat& img, vector<Point>& hits, double hit_t
                                                     ^
/usr/local/include/opencv2/gpu/gpu.hpp:1303:57: error: ‘vector’ has not been declared
     void computeConfidenceMultiScale(const GpuMat& img, vector<Rect>& found_loc
                                                         ^
/usr/local/include/opencv2/gpu/gpu.hpp:1303:63: error: expected ‘,’ or ‘...’ before ‘<’ token
     void computeConfidenceMultiScale(const GpuMat& img, vector<Rect>& found_loc
                                                               ^
/usr/local/include/opencv2/gpu/gpu.hpp:1835:5: error: ‘vector’ does not name a type
     vector<GpuMat> prevPyr_;
     ^
/usr/local/include/opencv2/gpu/gpu.hpp:1836:5: error: ‘vector’ does not name a type
     vector<GpuMat> nextPyr_;
     ^
/usr/local/include/opencv2/gpu/gpu.hpp:1838:5: error: ‘vector’ does not name a type
     vector<GpuMat> buf_;
     ^
/usr/local/include/opencv2/gpu/gpu.hpp:1839:5: error: ‘vector’ does not name a type
     vector<GpuMat> unused;
     ^
pa_stitching/CMakeFiles/pa_stitching_node.dir/build.make:62: recipe for target 'pa_stitching/CMakeFiles/pa_stitching_node.dir/src/main.cpp.o' failed
make[2]: *** [pa_stitching/CMakeFiles/pa_stitching_node.dir/src/main.cpp.o] Error 1
CMakeFiles/Makefile2:353: recipe for target 'pa_stitching/CMakeFiles/pa_stitching_node.dir/all' failed
make[1]: *** [pa_stitching/CMakeFiles/pa_stitching_node.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j8 -l8" failed

待问题解决后,发现

//#include <opencv2/nonfree/features2d.hpp>
//#include <opencv2/nonfree/nonfree.hpp>
//#include <opencv2/legacy/legacy.hpp>

等文件不能加入到工程,不然还是会报错如下:

/usr/local/include/opencv2/nonfree/features2d.hpp:81:5: error: ‘AlgorithmInfo’ does not name a type
     AlgorithmInfo* info() const;
     ^
In file included from /home/wds/catkin_ws/src/pa_stitching/include/Configure.h:18:0,
                 from /home/wds/catkin_ws/src/pa_stitching/src/main.cpp:2:
/usr/local/include/opencv2/nonfree/features2d.hpp:132:5: error: ‘AlgorithmInfo’ does not name a type
     AlgorithmInfo* info() const;
     ^
In file included from /home/wds/catkin_ws/src/pa_stitching/include/Configure.h:20:0,
                 from /home/wds/catkin_ws/src/pa_stitching/src/main.cpp:2:
/usr/local/include/opencv2/legacy/legacy.hpp:1750:53: error: ‘cv::EM’ has not been declared
     CvEMParams( int nclusters, int cov_mat_type=cv::EM::COV_MAT_DIAGONAL,
                                                     ^
/usr/local/include/opencv2/legacy/legacy.hpp:1751:36: error: ‘cv::EM’ has not been declared
                 int start_step=cv::EM::START_AUTO_STEP,
                                    ^
/usr/local/include/opencv2/legacy/legacy.hpp:1767:1: error: expected class-name before ‘{’ token
 {
 ^
/usr/local/include/opencv2/legacy/legacy.hpp:1770:34: error: ‘cv::EM’ has not been declared
     enum { COV_MAT_SPHERICAL=cv::EM::COV_MAT_SPHERICAL,
                                  ^
/usr/local/include/opencv2/legacy/legacy.hpp:1771:34: error: ‘cv::EM’ has not been declared
            COV_MAT_DIAGONAL =cv::EM::COV_MAT_DIAGONAL,


查阅了大量的参考后发现:造成错误的原因主要是由于ros在Kinect的版本中自带了opencv3(通过ros-kinect-opencv3安装),在目录/opt/ros/kinetic/include/opencv-3.1.0-dev下。cv3与cv2的不兼容造成了错误。

解决方法1:参考ROS官网给的解决方案,http://wiki.ros.org/opencv3;

1.)如果安装了OpenCV2和OpenCV3,在CMake中的find_package(OpenCV)将首先找到OpenCV3。如果要显式链接到OpenCV2,请使用find_package(OpenCV 2)。

2.)在ros中不能依赖cv_bridgeimage_geometry,因为他们在cmake文件中加入了opencv3的引用。并且加入了opencv3的包,如下

cv_brige的包包含了opencv3;

解决方法2:将ros依赖的cv_bridgeimage_geometry中opencv的版本改写成opencv2xx;

参考http://www.cnblogs.com/YouXiangLiThon/p/6298286.html:将cmake文件以及package文件中opencv3的版本全部改成opencv2:

问题即可解决

展开阅读全文

没有更多推荐了,返回首页