OpenCV 编译错误与非自由/feature2d.hpp.

OpenCV compiling error with nonfree/feature2d.hpp

本文关键字:feature2d hpp 自由 编译 错误 OpenCV      更新时间:2023-10-16

我正在尝试使用 Ubuntu 14.04 下的catkin_make在 ROS indigo 中编译C++代码。我收到以下错误:

/usr/local/include/opencv2/nonfree/features2d.hpp:73:21: error: ‘vector’ has not been declared
                     vector<KeyPoint>& keypoints) const;
                     ^
/usr/local/include/opencv2/nonfree/features2d.hpp:73:27: error: expected ‘,’ or ‘...’ before ‘<’ token
                     vector<KeyPoint>& keypoints) const;
                           ^
/usr/local/include/opencv2/nonfree/features2d.hpp:77:21: error: ‘vector’ has not been declared
                     vector<KeyPoint>& keypoints,
                     ^
/usr/local/include/opencv2/nonfree/features2d.hpp:77:27: error: expected ‘,’ or ‘...’ before ‘<’ token
                     vector<KeyPoint>& keypoints,

有没有人知道,问题可能是什么?请注意,此错误发生在OpenCV的feature2d.hpp中(因此它不是我创建的文件)。我已经尝试重新安装OpenCV和ROS,但这并没有解决错误。

如果有人知道如何解决这个问题,我将不胜感激。

谢谢

编辑:这是CMakeLists.txt:

cmake_minimum_required (VERSION 2.8.3)
project (test)
set (test_VERSION "1.0.0")
find_package( OpenCV REQUIRED )         
if ( NOT OpenCV_FOUND )
  message(FATAL_ERROR "Package OpenCV required, but not found!")
endif( NOT OpenCV_FOUND )
find_package( Eigen3 REQUIRED )         
include_directories(
  ${EIGEN3_INCLUDE_DIR}             
  ${CMAKE_CURRENT_SOURCE_DIR}/include
  ${OpenCV_INCLUDE_DIRS}
)
set (SOURCE
  src/test.cpp)
add_library (test ${SOURCE})
set_target_properties (test PROPERTIES
  COMPILE_FLAGS "-std=c++11")
target_link_libraries( test ${OpenCV_LIBS} ${EIGEN3_LIBRARY_DIRS})

我有点修复它,但我想这不是正确的方法:

ROS已经推出了OpenCV版本。在我的电脑上,我还安装了一个单独的较新的OpenCV版本。我通过更改目录中两个文件夹的名称来修复它 opencvopencv2 目录 /opt/ros/indigo/include .现在,编译器不再使用ROS的OpenCV,而是我安装的OpenCV,它正在解决我的问题。

再说一次,我认为这不是应该这样做的方式,所以如果有人有更好的主意,请告诉我!

尝试在

包含opencv2之前编写:

#include <vector>
using namespace std;