使用OpenCV 2.4.9构建ROS软件包时出现问题

时间:2018-12-28 19:19:54

标签: c++ opencv cmake ros catkin

我正在尝试使用catkin build构建ROS软件包。 该软件包是与OpenCV2一起运行的,因此我从源代码安装了OpenCV 2.4.9。

运行catkin build时遇到一些错误。情况如下:

首先,我更改了CMakeLists.txt,以便它可以找到正确版本的OpenCV。
然后,我添加了#include <vector>,并将vector文件中std::vector的每个出现都更改为opencv2/nonfree/features2d.hpp,因为我得到了错误,即未声明vector并且错误消失了。

我得到的另一个错误是:

In file included from /usr/local/include/opencv2/nonfree/nonfree.hpp:46:0,
from /home/vm/catkin_ws/src/ogm_merging/ogm_evaluation/feature_evaluation/include/feature_evaluation/feature_evaluation_metrics/feature_metrics.h:29:
from /home/vm/catkin_ws/src/ogm_merging/ogm_evaluation/feature_evaluation/src/feature_evaluation/feature_evaluation_metrics/feature_metrics.cpp:19:
 /usr/local/include/opencv2/nonfree/features2d.hpp:133:5:   
 error: ‘AlgorithmInfo’ does not name a type
      AlgorithmInfo* info() const;
      ^

nonfree / features2d.hpp如下:

#ifndef __OPENCV_NONFREE_FEATURES_2D_HPP__
#define __OPENCV_NONFREE_FEATURES_2D_HPP__

#include "opencv2/features2d/features2d.hpp"

#ifdef __cplusplus

namespace cv
{

/*!
 SIFT implementation.
 The class implements SIFT algorithm by D. Lowe.
*/
class CV_EXPORTS_W SIFT : public Feature2D
{
public:

    CV_WRAP explicit SIFT( int nfeatures=0, int nOctaveLayers=3,
          double contrastThreshold=0.04, double edgeThreshold=10,
          double sigma=1.6);

    //! returns the descriptor size in floats (128)
    CV_WRAP int descriptorSize() const;

    //! returns the descriptor type
    CV_WRAP int descriptorType() const;

    //! finds the keypoints using SIFT algorithm
    void operator()(InputArray img, InputArray mask,
                    std::vector<KeyPoint>& keypoints) const;
    //! finds the keypoints and computes descriptors for them using SIFT algorithm.
    //! Optionally it can compute descriptors for the user-provided keypoints
    void operator()(InputArray img, InputArray mask,
                    std::vector<KeyPoint>& keypoints,
                    OutputArray descriptors,
                    bool useProvidedKeypoints=false) const;

    AlgorithmInfo* info() const;

    void buildGaussianPyramid( const Mat& base, std::vector<Mat>& pyr, int nOctaves ) const;

    void buildDoGPyramid( const std::vector<Mat>& pyr, std::vector<Mat>& dogpyr ) const;

    void findScaleSpaceExtrema( const std::vector<Mat>& gauss_pyr, const std::vector<Mat>& dog_pyr,
                                std::vector<KeyPoint>& keypoints ) const;
protected:
    void detectImpl( const Mat& image, std::vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
    void computeImpl( const Mat& image, std::vector<KeyPoint>& keypoints, Mat& descriptors ) const;

    CV_PROP_RW int nfeatures;
    CV_PROP_RW int nOctaveLayers;
    CV_PROP_RW double contrastThreshold;
    CV_PROP_RW double edgeThreshold;
    CV_PROP_RW double sigma;
};

typedef SIFT SiftFeatureDetector;
typedef SIFT SiftDescriptorExtractor;

} /* namespace cv */
#endif /* __cplusplus */
#endif

我不想更改为OpenCV 3并添加额外的模块,正如这里的许多人所说,我想使用OpenCV2来运行此程序。

我尝试包含诸如features2d / features2d.hpp的core / core.hpp之类的文件,但没有任何变化。 AlgorithmInfo类在哪里定义,以便我可以使用它?

我正在使用Ubuntu 16.04和ROS Kinetic。

更新:它可与Ubuntu 14.04,ROS Indigo和Opencv 2.4一起使用,因此问题必须与ROS或Ubuntu版本有关。有任何想法吗?

谢谢。

1 个答案:

答案 0 :(得分:1)

ROS和OpenCV通过opencv_bridge一起工作。我不确定这是否可以解决您的第一个问题,但是您似乎没有使用opencv_bridge来解决至少一些问题。