Ask Your Question

idkm1's profile - activity

2018-11-30 18:02:47 -0500 received badge  Popular Question (source)
2015-06-12 08:18:35 -0500 commented question Converting ros image msg to cv image issue

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.

2015-06-12 01:05:58 -0500 asked a question Converting ros image msg to cv image issue

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}
 )
2015-06-11 20:06:22 -0500 received badge  Organizer (source)