在ROS下使用CMakeList编译OpenCV

时间:2015-09-30 08:40:32

标签: c++ opencv cmake ros

我正在尝试使用 CmakeList.txt (在 ROS (机器人操作系统)下)编译 openCV 代码,我的CmakeList正在运行,因为在另一台PC上运行良好。我安装了OpenCV并在openCV示例目录中使用g ++和一些标志编译了示例,编译成功。但是当我想使用CmakeList编译我的其他代码时,我得到错误

CMakeFiles/aupark_node.dir/src/wrapper.cpp.o: In function `Wrapper::set_head_image(std::string)':
wrapper.cpp:(.text+0x2ef1): undefined reference to `cv::imread(cv::String const&, int)'
在wrapper.cpp中的

我有所有适当的包含。

#include <opencv2/opencv.hpp>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>

我的CMakeList.txt在这里:

cmake_minimum_required(VERSION 2.8.3)
project(aupark)

set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
find_package(catkin REQUIRED COMPONENTS cmake_modules roscpp gencpp moveit_ros_planning_interface moveit_msgs cv_bridge)
find_package(Eigen REQUIRED)
include_directories(${EIGEN_INCLUDE_DIRS})
add_definitions(${EIGEN_DEFINITIONS})

catkin_package()

add_executable(aupark_node src/aupark_node.cpp src/wrapper.cpp src/wrapper.h)
target_link_libraries(aupark_node ${catkin_LIBRARIES})

有什么不对?

输出pkg-config opencv --libs:

-L/usr/local/lib
-lopencv_shape 
-lopencv_stitching 
-lopencv_objdetect 
-lopencv_superres  
-lopencv_videostab 
-lopencv_calib3d 
-lopencv_features2d  
-lopencv_highgui 
-lopencv_videoio 
-lopencv_imgcodecs 
-lopencv_video 
-lopencv_photo 
-lopencv_ml 
-lopencv_imgproc 
-lopencv_flann 
-lopencv_viz 
-lopencv_core 
-lopencv_hal 

1 个答案:

答案 0 :(得分:6)

您未在CMakeLists.txt

中与OpenCV相关联

为此,请在顶部添加find_package(OpenCV REQUIRED),然后将目标链接到它:

target_link_libraries(aupark_node ${catkin_LIBRARIES} ${OpenCV_LIBS})

可以在the OpenCV documentation中找到有关如何将OpenCV与cmake一起使用的最小示例。