ROS ImagePtr和图像编译混淆

时间:2015-07-24 20:44:44

标签: image compilation ros

我正在尝试创建一个包含两个图像的自定义消息。这是自定义消息文件:

Header header
sensor_msgs/Image leftimage
sensor_msgs/Image rightimage

以下是我尝试使用自定义消息从我的立体相机通过ROS发布图像的文件:

sensor_msgs::ImagePtr leftmsg;
sensor_msgs::ImagePtr rightmsg;
leftmsg = cv_bridge::CvImage(std_msgs::Header(), "mono8", leftframe).toImageMsg();
rightmsg = cv_bridge::CvImage(std_msgs::Header(), "mono8", rightframe).toImageMsg();
stereo.leftimage = leftmsg;
stereo.rightimage = rightmsg;
stereo_pub.publish(stereo);

但是,当我catkin_make

时,我收到以下编译错误
    error: no match for ‘operator=’ (operand types are ‘duo_cam::Stereo_<std::allocator<void> >::_leftimage_type {aka sensor_msgs::Image_<std::allocator<void> >}’ and ‘sensor_msgs::ImagePtr {aka boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > >}’)
            stereo.leftimage = leftmsg;
                             ^
    note: candidate is:
    In file included from /opt/ros/indigo/include/image_transport/publisher.h:39:0,
             from /opt/ros/indigo/include/image_transport/image_transport.h:38,
    sensor_msgs::Image_<std::allocator<void> >& sensor_msgs::Image_<std::allocator<void> >::operator=(const sensor_msgs::Image_<std::allocator<void> >&)
     struct Image_
            ^

我该如何纠正?我已经在使用toImageMsg()函数,我在网上看到它将ImagePtr变成了一个Image,因此不确定出了什么问题。非常感谢任何帮助!

1 个答案:

答案 0 :(得分:3)

根据the documentationtoImageMsg的签名是

sensor_msgs::ImagePtr toImageMsg() const;

ImagePtr转换为ImageCvImage用于将OpenCV图像转换为ROS图像)。您将leftmsgrightmsg声明为ImagePtr这一事实也可以看出这一点;如果toImageMsg将返回Image,则无效。

要获取Image的{​​{1}},只需取消引用指针即可。以下应该有效:

ImagePtr