ROS CV_Bridge链接:未定义引用cv_bridge :: toCvShare(...)

时间:2016-04-26 07:09:04

标签: opencv boost linker ros

我最近建立了一台带有ROS和OpenCV的新计算机。但在第一个测试项目中,我无法将ROS cv_bridge正确链接

rosmake之后的错误是:

[100%] Building CXX object CMakeFiles/motion_detector.dir/src/motion_detector.cpp.o
Linking CXX executable bin/motion_detector
CMakeFiles/motion_detector.dir/src/motion_detector.cpp.o: In function `imageCallback(boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > const> const&)':
/home/sh/workspace/ros/motion_detection_01/src/motion_detector.cpp:11: undefined reference to `cv_bridge::toCvShare(boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > const> const&, std::string const&)'

但是cv_bridge就在那里。运行roscd cv_bridge显示我的文件夹和所有。 谷歌并没有真正展示我对“未定义的对cv_bridge :: .. 的引用”的看法。令我怀疑的是,错误显示'对cv_bridge :: toCvShare的未定义引用( boost :: shared_ptr

你可以帮我解决这个问题吗? THX!

以下是我的项目文件:

motion_detection.cpp

#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h>

void imageCallback(const sensor_msgs::ImageConstPtr& msg)
{
  try
  {
    //cv::imshow("view", cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8)->image);
    cv::Mat _img = cv_bridge::toCvShare(msg , "bgr8")->image;
...

的CMakeLists.txt

cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

include_directories(/usr/local/include)
include_directories(/usr/local/include/opencv)
include_directories(/usr/local/include/opencv2)

link_directories(/usr/local/lib)

# Set the build type.  Options are:
#  Coverage       : w/ debug symbols, w/o optimization, w/ code-coverage

...

set(ROS_LINK_FLAGS "-lopencv_core -lopencv_highgui -lopencv_legacy -lopencv_imgproc -lopencv_features2d")

...

rosbuild_add_executable(motion_detector src/motion_detector.cpp)
target_link_libraries(motion_detector opencv_core opencv_highgui opencv_nonfree)

的manifest.xml

<package>
  <description brief="motion_detection_01">

     motion_detection_01

  </description>
  <author>basti</author>
  <license>BSD</license>
  <review status="unreviewed" notes=""/>
  <url>http://ros.org/wiki/motion_detection_01</url>

  <depend package="std_msgs"/>
  <depent package="cv_bridge"/> 
  <depend package="genmsg"/>
  <depend package="sensor_msgs"/>
  <depend package="rospy"/>
  <depend package="roscpp"/>
  <depend package="roscpp"/>
  <depend package="image_transport"/>

</package>

0 个答案:

没有答案