使用图像传输压缩和boost库c ++

时间:2014-01-07 18:00:15

标签: c++ opencv boost ros

我有一个回调,我需要在订阅ROS图像主题后运行:

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

如您所见,回调有两个参数,图像和数字。我知道可以使用boost库以这种方式向回调发送两个参数:

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

但我还想使用压缩传输插件。所以,如果我写

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

我无法构建代码:

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&)

那么,我应该如何编写用户线路代码?感谢

1 个答案:

答案 0 :(得分:0)

您似乎需要使用 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()
        )

所以我假设你只需要明确地传递tracked_object参数:

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

(您很可能只能通过nullptrNULL0。我没有使用此处显示的库的经验。)