-
为节约带宽提高效率采用jpeg:
sensor_msgs::CompressedImage image_msg;
ros::Publisher img_pub = n.advertise<sensor_msgs::CompressedImage>(“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); -
为可视化调试将sensor_msgs::CompressedImage解压重发布为sensor_msgs::Image,命令如下(假如image1是jpeg,image2是raw):
rosrun image_transport republish compressed in/compressed:=image1 out:=/camera_ligrip/image2 -
启动可视化工具
rosrun rviz rviz
软件界面 左下角Add-> By topic选中重发布的topic Image节点 -> OK