【问题标题】:Problem building a ROS package with OpenCV 2.4.9使用 OpenCV 2.4.9 构建 ROS 包时出现问题
【发布时间】:2019-05-26 13:30:32
【问题描述】:

我正在尝试构建一个 ROS 包,使用 catkin build。 这个包是用 OpenCV2 运行的,所以我从源代码安装了 OpenCV 2.4.9。

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

起初,我更改了 CMakeLists.txt,以便它可以找到正确的 OpenCV 版本。
然后,我添加了#include <vector>,并在opencv2/nonfree/features2d.hpp 文件中将vector 的每次出现都更改为std::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 版本有关。有什么想法吗?

提前谢谢你。

【问题讨论】:

  • Online docs 说要使用AlgorithmInfo 你需要#include &lt;core.hpp&gt;
  • 即使使用#include "opencv2/core/core.hpp" 我也会遇到同样的错误
  • 您是否为您的 opencv 版本(github->releases)下载/使用了正确的额外模块版本?
  • @Micka 据我所知,OpenCV 版本 2 没有额外的模块。额外的模块在 OpenCV3 之后是分开的。如果我错了,请纠正我。对于 Github 中的 OpenCV 2.4.9->Releases 只是源代码。
  • 可能是对的,我不记得了,抱歉。你试过不同的 2.4.X 版本吗?还是有什么特殊的原因要使用 2.4.9?

标签: c++ opencv cmake ros catkin


【解决方案1】:

ROS 和 OpenCV 通过opencv_bridge 协同工作。我不确定这是否能解决您最初的问题,但您似乎没有使用opencv_bridge,它至少可以解决您的一些问题。

【讨论】:

  • 谢谢,我试试看!
猜你喜欢
  • 2016-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-13
  • 2021-05-08
  • 1970-01-01
相关资源
最近更新 更多