Ask Your Question
0

Sensor msg to an opencv image

asked 2015-06-12 08:23:21 -0600

idkm1 gravatar image

I am attempting to convert a sensor_msgs/Image msg into something displayable in opencv. I am using cv_bridge to accomplish this conversion. When I catkin build, I get:

CMakeFiles/image_reader_node.dir/src/image_reader_node.cpp.o: In function `call_back(boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > const> const&)':
image_reader_node.cpp:(.text+0x38): undefined reference to `cv_bridge::toCvCopy(boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > const> const&, std::string const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/chris/indigo/Baxter_ws/devel/lib/image_reader/image_reader_node] Error 1
make[1]: *** [CMakeFiles/image_reader_node.dir/all] Error 2
make: *** [all] Error 2

Here is my callback function and includes:

#include "opencv2/opencv.hpp"
#include <iostream>
#include <ros/ros.h>
#include "sensor_msgs/Image.h"
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>

void call_back(const sensor_msgs::ImageConstPtr& msg) {

          cv_bridge::CvImagePtr cv_ptr;
          try
          {
            cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);
          }
          catch (cv_bridge::Exception& e)
          {
            ROS_ERROR("cv_bridge exception: %s", e.what());
            return;
          }

          namedWindow("please", CV_WINDOW_AUTOSIZE);
          imshow("please", cv_ptr->image);
          waitKey(5);
      }

My CMakeLists.txt just incase:

cmake_minimum_required(VERSION 2.8.3)
project(image_reader)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  sensor_msgs
)
find_package( OpenCV REQUIRED )

catkin_package(
  INCLUDE_DIRS include
  LIBRARIES image_reader_node
  CATKIN_DEPENDS roscpp sensor_msgs
  DEPENDS system_lib
)

include_directories(
  ${catkin_INCLUDE_DIRS}
  ${OpenCV_INCLUDE_DIRS}
)

 add_executable(image_reader_node src/image_reader_node.cpp)

 add_dependencies(image_reader_node ${catkin_EXPORTED_TARGETS})

 target_link_libraries(image_reader_node
    ${catkin_LIBRARIES} ${OpenCV_LIBRARIES}
 )
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2015-06-12 09:22:48 -0600

dornhege gravatar image

You are using cv_bridge, but it isn't mentioned in the CMakeLists.txt at all. You should add that dependency to make it compile.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2015-06-12 08:23:21 -0600

Seen: 609 times

Last updated: Jun 12 '15