ROS1 图像数据转发

  1. 为节约带宽提高效率采用jpeg:
    sensor_msgs::CompressedImage image_msg;
    ros::Publisher img_pub = n.advertise(“image1”, 10);
    image_msg.format=“jpeg” ;
    image_msg.data.resize(jpeg_data_size);
    memcpy(image_msg.data.data(),jpeg_data,jpeg_data_size);
    image_msg.header.frame_id = “camera”;
    image_msg.header.stamp.sec = img_ts/1000000;
    image_msg.header.stamp.nsec = img_ts%1000000*1000;
    img_pub.publish(image_msg);

  2. 为可视化调试将sensor_msgs::CompressedImage解压重发布为sensor_msgs::Image,命令如下(假如image1是jpeg,image2是raw):
    rosrun image_transport republish compressed in/compressed:=image1 out:=/camera_ligrip/image2

  3. 启动可视化工具
    rosrun rviz rviz
    软件界面 左下角Add-> By topic选中重发布的topic Image节点 -> OK
    ROS1 图像数据转发_第1张图片

你可能感兴趣的:(ros)