ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

using image transport compression and boost library c++

asked 2014-01-02 01:53:57 -0500

rosmat88 gravatar image

updated 2014-01-05 19:20:48 -0500

tfoote gravatar image

Hi, I have a callback that I need to run after subscribing to a ROS image topic:

void imageCallback(const sensor_msgs::ImageConstPtr& original_image, int n) {
   ..
}

as you can see, the callback takes two parameters, the image and a number. I know that is possible to use boost library to send two parameters to the callback in this way:

image_transport::Subscriber sub = it.subscribe("/camera1/RGB", 1, boost::bind(imageCallback,_1, 1));

but I would like to use also a compression transport plug-in. So, if I write

 image_transport::Subscriber sub = it.subscribe("/camera1/RGB", 1, boost::bind(imageCallback, _1, 1),image_transport::TransportHints::TransportHints("compressed"));

I cannot build the code:

error: no matching function for call to ‘image_transport::ImageTransport::subscribe(const char [13], int, boost::_bi::bind_t<void, void (*)(const sensor_msgs::ImageConstPtr&, int), boost::_bi::list2<boost::arg<1>, boost::_bi::value<int> > >, image_transport::TransportHints)’
/opt/ros/fuerte/stacks/image_common/image_transport/include/image_transport/image_transport.h:40: note: candidates are: image_transport::Subscriber image_transport::ImageTransport::subscribe(const std::string&, uint32_t, const boost::function<void(const sensor_msgs::ImageConstPtr&)>&, const ros::VoidPtr&, const image_transport::TransportHints&)
/opt/ros/fuerte/stacks/image_common/image_transport/include/image_transport/image_transport.h:48: note:                 image_transport::Subscriber image_transport::ImageTransport::subscribe(const std::string&, uint32_t, void (*)(const sensor_msgs::ImageConstPtr&), const image_transport::TransportHints&)

So, how I should write the subscriber line code? Thanks

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2014-01-07 21:37:14 -0500

Wolf gravatar image

The function declaration with defaults is (see image_transport.h):

/**
   * \brief Subscribe to an image topic, version for arbitrary boost::function object.
   */
  Subscriber subscribe(const std::string& base_topic, uint32_t queue_size,
                       const boost::function<void(const sensor_msgs::ImageConstPtr&)>& callback,
                       const ros::VoidPtr& tracked_object = ros::VoidPtr(),
                       const TransportHints& transport_hints = TransportHints());

If you just add your TransportHints, the compiler will assume is to be the 4th arg, where a ros::VoidPtr is expected, which causes the compile error. I think your function call should be:

 image_transport::Subscriber sub = it.subscribe("/camera1/RGB", 1, boost::bind(imageCallback, _1, 1), ros::VoidPtr(), image_transport::TransportHints::TransportHints("compressed"));
edit flag offensive delete link more

Comments

Yes, this worked for me. I didn't think to look at class definition. Thanks

rosmat88 gravatar image rosmat88  ( 2014-01-13 20:01:37 -0500 )edit
1

answered 2014-01-08 01:06:44 -0500

Hamid Didari gravatar image

Looks like you need to use this overload:

Subscriber image_transport::ImageTransport::subscribe(
        const std::string &     base_topic, 
        uint32_t                queue_size, 
        const boost::function<void(const sensor_msgs::ImageConstPtr &)>& callback, 
        const ros::VoidPtr &    tracked_object = ros::VoidPtr(), 
        const TransportHints &  transport_hints = TransportHints()
        )

So I'd assume you just need to explicitely pass the tracked_object parameter:

image_transport::Subscriber sub = it.subscribe(
    "/camera1/RGB", 
    1, 
    boost::bind(imageCallback, _1, 1),
    ros::VoidPtr(),                       // THIS ADDED
    image_transport::TransportHints::TransportHints("compressed")
);
edit flag offensive delete link more

Comments

Thanks, this is working too.

rosmat88 gravatar image rosmat88  ( 2014-01-13 20:01:54 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-01-02 01:53:57 -0500

Seen: 1,685 times

Last updated: Jan 08 '14