Use the rosbag command to convert the compressed image data format to raw
I recently used a new camera, and the data set images I obtained are in compressed format. When using kalibr to calibrate and run the SLAM code, I found that the compression format often encounters problems, which are recorded here.
1 kalibr uses compressed image format
Reference blog: kalibr that supports compressed image messages, error TypeError: Conversion is only valid for arrays with 1 or 2 dimensions
Modify the function getImage() in the file ImageDatasetReader.py:
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 uncompress
self.uncompress = uncompress
img_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 to raw
Reference blog
https://blog.csdn.net/qq_25458977/article/details/109358577
https://answers.ros.org/question/333064/unable-to-show-depth-cloud-with-compressed-rgb/
The compressed image topic name of the Hikvision camera I used contains compressed. If I use the /hikrobot_camera/rgb/compressed topic directly, a warning will appear: Then I found
someone asking this question on the second webpage, and mentioned: Because this command will automatically add compressed to the original topic name, it needs to be removed when republishing, as follows:
rosrun image_transport republish compressed in:=/hikrobot_camera/rgb raw out:=/hikrobot_camera/rgb
The /hikrobot_camera/rgb topic obtained in this way is of raw type:
3 Use image_view to view compressed images
rosrun image_view image_view image:=/hikrobot_camera/rgb _image_transport:='compressed'