本文主要是介绍利用rosbag命令将compressed图像数据格式转为raw,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
利用rosbag命令将compressed图像数据格式转为raw
- 1 kalibr使用compressed图像格式
- 2 compressed转为raw
- 3 使用image_view查看compressed图像
最近用了一个新的相机,拿到的数据集图像是经过压缩的compress格式,在使用kalibr标定以及运行SLAM代码的时候发现压缩格式经常遇到问题,在此进行记录.
1 kalibr使用compressed图像格式
参考博客:支持compressed image消息的kalibr,错误TypeError: Conversion is only valid for arrays with 1 or 2 dimensions
修改文件ImageDatasetReader.py中的函数getImage():
def getImage(self,idx):topic, data, stamp = self.bag._read_message(self.index[idx].position)ts = acv.Time( data.header.stamp.secs, data.header.stamp.nsecs )if data._type == 'mv_cameras/ImageSnappyMsg':if self.uncompress is None:from snappy import uncompressself.uncompress = uncompressimg_data = np.reshape(self.uncompress(np.fromstring(data.data, dtype='uint8')),(data.height,data.width), order="C")elif data._type == 'sensor_msgs/CompressedImage':np_arr = np.fromstring(data.data, np.uint8)img_data_rgb = cv2.imdecode(np_arr, cv2.IMREAD_COLOR)img_data = cv2.cvtColor(img_data_rgb,cv2.COLOR_BGR2GRAY)else:img_data = np.array(self.CVB.imgmsg_to_cv2(data, "mono8"))return (ts, img_data)
2 compressed转为raw
参考博客
https://blog.csdn.net/qq_25458977/article/details/109358577
https://answers.ros.org/question/333064/unable-to-show-depth-cloud-with-compressed-rgb/
我使用的海康相机本身的压缩图像topic名称是含有compressed的,如果直接使用/hikrobot_camera/rgb/compressed话题,会出现警告:
然后我在第二个网页里找到有人问了这个问题,提到说因为这个指令会自动对在原始topic名称的基础上添加compressed,在republish的时候所以要去掉,如下:
rosrun image_transport republish compressed in:=/hikrobot_camera/rgb raw out:=/hikrobot_camera/rgb
这样得到的/hikrobot_camera/rgb话题就是就是raw类型了:
3 使用image_view查看compressed图像
rosrun image_view image_view image:=/hikrobot_camera/rgb _image_transport:='compressed'
这篇关于利用rosbag命令将compressed图像数据格式转为raw的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!