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

Problem building a ROS package with OpenCV 2.4.9

本文关键字:ROS 包时出 问题 构建 OpenCV 使用      更新时间:2023-10-16

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

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

起初,我更改了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;
^

非自由/特征2d.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

我不想更改为OpenCV3并添加额外的模块,正如这里的许多人所说,我想用OpenCV2运行这个模块。

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

我使用的是Ubuntu 16.04和ROS Kinetic。

更新:它适用于Ubuntu 14.04、ROS Indigo和Opencv 2.4,所以问题一定与ROS或Ubuntu版本有关。有什么想法吗?

提前谢谢。

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