Converting ros image msg to cv image issue

asked 2015-06-11 20:06:22 -0500

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;
            cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);
          catch (cv_bridge::Exception& e)
            ROS_ERROR("cv_bridge exception: %s", e.what());

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

My CMakeLists.txt just incase:

cmake_minimum_required(VERSION 2.8.3)

find_package(catkin REQUIRED COMPONENTS
find_package( OpenCV REQUIRED )

  INCLUDE_DIRS include
  LIBRARIES image_reader_node
  CATKIN_DEPENDS roscpp sensor_msgs
  DEPENDS system_lib


 add_executable(image_reader_node src/image_reader_node.cpp)

 add_dependencies(image_reader_node ${catkin_EXPORTED_TARGETS})

    ${catkin_LIBRARIES} ${OpenCV_LIBRARIES}
edit retag flag offensive close merge delete


Why are you placing this on the OpenCV forum when there is an identical one for ROS?

StevenPuttemans gravatar imageStevenPuttemans ( 2015-06-12 05:51:57 -0500 )edit

I believe the problem is not with ros, but OpenCV. My compiler is saying there is no matching cv_bridge::toCvCopy function with the arguments I have provided.

idkm1 gravatar imageidkm1 ( 2015-06-12 08:18:35 -0500 )edit

Those are no actual OpenCv functions but ROS wrappers for the OpenCV module in ROS. So again, wrong forum....

StevenPuttemans gravatar imageStevenPuttemans ( 2015-06-12 12:44:43 -0500 )edit