从bag文件中提取RGB图像帧:rosbag.bag.ROSBagException: 不支持的压缩类型:lz4

huangapple go评论78阅读模式
英文:

extracting RGB image frames from the bag file: rosbag.bag.ROSBagException: unsupported compression type: lz4

问题

这段代码似乎无法正确读取消息。你在这里可能犯了一个错误。错误信息显示了它无法支持压缩类型lz4

你可以尝试解决这个问题的方法是,确保你的代码支持lz4压缩类型。你可以查看rosbag库的文档,看看如何处理这种压缩类型。

如果你不确定如何处理,你也可以考虑尝试使用其他支持的压缩类型,例如bz2或者不使用压缩。

英文:

I have a piece of code that I want to extract the RGB frames from the bag file. Code is as follows:

import os
import argparse
import pdb

import cv2

import rosbag
from sensor_msgs.msg import Image
from cv_bridge import CvBridge

bag_file = './bag_files/20230707_152832.bag'
output_dir= './frames/rgb_bag_output'

# topic can be obtained by using the following command in terminal
#  time rosbag info ./bag_files/20230707_152832.bag
image_topic = '/device_0/sensor_1/Color_0/image/data'

bag = rosbag.Bag(bag_file, "r")
bridge = CvBridge()

count = 0
for topic, msg, t in bag.read_messages(topics=[image_topic]):
    cv_img = bridge.imgmsg_to_cv2(msg, desired_encoding= "rgb8")#"passthrough")

    cv2.imwrite(os.path.join(output_dir, "frame%06i.png" % count), cv_img)
    print("Wrote image %i" % count)
    count += 1

bag.close()

But it seems it does not run the for loop at all. I ran the following command in terminal to get the topic info:

 time rosbag info ./bag_files/20230707_152832.bag
path:         ./bag_files/20230707_152832.bag
version:      2.0
duration:     12.6s
start:        Jan 01 1970 07:30:00.00 (0.00)
end:          Jan 01 1970 07:30:12.58 (12.58)
size:         410.0 MB
messages:     17874
compression:  lz4 [757/757 chunks; 65.32%]
uncompressed: 627.0 MB @ 49.8 MB/s
compressed:   409.6 MB @ 32.5 MB/s (65.32%)
types:        diagnostic_msgs/KeyValue  [cf57fdc6617a881a88c16e768132149c]
geometry_msgs/Transform   [ac9eff44abf714214112b05d54a3cf9b]
realsense_msgs/StreamInfo [311d7e24eac31bb87271d041bf70ff7d]
sensor_msgs/CameraInfo    [c9a58c1b0b154e0e6da7578cb991d214]
sensor_msgs/Image         [060021388200f6f0f447d0fcd9c64743]
std_msgs/Float32          [73fcbf46b49191e672908e50842a83d4]
std_msgs/String           [992ce8a1687cec8c8bd883ec73ca41d1]
std_msgs/UInt32           [304a39449588c7f8ce2df6e8001c5fce]
topics:       /device_0/info                                                      13 msgs    : diagnostic_msgs/KeyValue 
/device_0/sensor_0/Depth_0/image/data                              378 msgs    : sensor_msgs/Image        
/device_0/sensor_0/Depth_0/image/metadata                         9072 msgs    : diagnostic_msgs/KeyValue 
/device_0/sensor_0/Depth_0/info                                      1 msg     : realsense_msgs/StreamInfo
/device_0/sensor_0/Depth_0/info/camera_info                          1 msg     : sensor_msgs/CameraInfo   
/device_0/sensor_0/Depth_0/tf/0                                      1 msg     : geometry_msgs/Transform  
/device_0/sensor_0/info                                              2 msgs    : diagnostic_msgs/KeyValue 
/device_0/sensor_0/option/Asic_Temperature/description               1 msg     : std_msgs/String          
/device_0/sensor_0/option/Asic_Temperature/value                     1 msg     : std_msgs/Float32         
/device_0/sensor_0/option/Depth_Units/description                    1 msg     : std_msgs/String          
/device_0/sensor_0/option/Depth_Units/value                          1 msg     : std_msgs/Float32         
/device_0/sensor_0/option/Emitter_Always_On/description              1 msg     : std_msgs/String          
/device_0/sensor_0/option/Emitter_Always_On/value                    1 msg     : std_msgs/Float32         
/device_0/sensor_0/option/Emitter_Enabled/description                1 msg     : std_msgs/String          
/device_0/sensor_0/option/Emitter_Enabled/value                      1 msg     : std_msgs/Float32         
/device_0/sensor_0/option/Emitter_On_Off/description                 1 msg     : std_msgs/String          
/device_0/sensor_0/option/Emitter_On_Off/value                       1 msg     : std_msgs/Float32         
/device_0/sensor_0/option/Enable_Auto_Exposure/description           1 msg     : std_msgs/String          
/device_0/sensor_0/option/Enable_Auto_Exposure/value                 1 msg     : std_msgs/Float32         
/device_0/sensor_0/option/Error_Polling_Enabled/description          1 msg     : std_msgs/String          
/device_0/sensor_0/option/Error_Polling_Enabled/value                1 msg     : std_msgs/Float32         
/device_0/sensor_0/option/Exposure/description                       1 msg     : std_msgs/String          
/device_0/sensor_0/option/Exposure/value                             1 msg     : std_msgs/Float32         
/device_0/sensor_0/option/Frames_Queue_Size/description              1 msg     : std_msgs/String          
/device_0/sensor_0/option/Frames_Queue_Size/value                    1 msg     : std_msgs/Float32         
/device_0/sensor_0/option/Gain/description                           1 msg     : std_msgs/String          
/device_0/sensor_0/option/Gain/value                                 1 msg     : std_msgs/Float32         
/device_0/sensor_0/option/Global_Time_Enabled/description            1 msg     : std_msgs/String          
/device_0/sensor_0/option/Global_Time_Enabled/value                  1 msg     : std_msgs/Float32         
/device_0/sensor_0/option/Hdr_Enabled/description                    1 msg     : std_msgs/String          
/device_0/sensor_0/option/Hdr_Enabled/value                          1 msg     : std_msgs/Float32         
/device_0/sensor_0/option/Inter_Cam_Sync_Mode/description            1 msg     : std_msgs/String          
/device_0/sensor_0/option/Inter_Cam_Sync_Mode/value                  1 msg     : std_msgs/Float32         
/device_0/sensor_0/option/Laser_Power/description                    1 msg     : std_msgs/String          
/device_0/sensor_0/option/Laser_Power/value                          1 msg     : std_msgs/Float32         
/device_0/sensor_0/option/Output_Trigger_Enabled/description         1 msg     : std_msgs/String          
/device_0/sensor_0/option/Output_Trigger_Enabled/value               1 msg     : std_msgs/Float32         
/device_0/sensor_0/option/Projector_Temperature/description          1 msg     : std_msgs/String          
/device_0/sensor_0/option/Projector_Temperature/value                1 msg     : std_msgs/Float32         
/device_0/sensor_0/option/Sequence_Id/description                    1 msg     : std_msgs/String          
/device_0/sensor_0/option/Sequence_Id/value                          1 msg     : std_msgs/Float32         
/device_0/sensor_0/option/Sequence_Name/description                  1 msg     : std_msgs/String          
/device_0/sensor_0/option/Sequence_Name/value                        1 msg     : std_msgs/Float32         
/device_0/sensor_0/option/Sequence_Size/description                  1 msg     : std_msgs/String          
/device_0/sensor_0/option/Sequence_Size/value                        1 msg     : std_msgs/Float32         
/device_0/sensor_0/option/Stereo_Baseline/description                1 msg     : std_msgs/String          
/device_0/sensor_0/option/Stereo_Baseline/value                      1 msg     : std_msgs/Float32         
/device_0/sensor_0/option/Visual_Preset/description                  1 msg     : std_msgs/String          
/device_0/sensor_0/option/Visual_Preset/value                        1 msg     : std_msgs/Float32         
/device_0/sensor_0/post_processing                                   9 msgs    : std_msgs/String          
/device_0/sensor_1/Color_0/image/data                              378 msgs    : sensor_msgs/Image        
/device_0/sensor_1/Color_0/image/metadata                         7938 msgs    : diagnostic_msgs/KeyValue 
/device_0/sensor_1/Color_0/info                                      1 msg     : realsense_msgs/StreamInfo
/device_0/sensor_1/Color_0/info/camera_info                          1 msg     : sensor_msgs/CameraInfo   
/device_0/sensor_1/Color_0/tf/0                                      1 msg     : geometry_msgs/Transform  
/device_0/sensor_1/info                                              2 msgs    : diagnostic_msgs/KeyValue 
/device_0/sensor_1/option/Auto_Exposure_Priority/description         1 msg     : std_msgs/String          
/device_0/sensor_1/option/Auto_Exposure_Priority/value               1 msg     : std_msgs/Float32         
/device_0/sensor_1/option/Backlight_Compensation/description         1 msg     : std_msgs/String          
/device_0/sensor_1/option/Backlight_Compensation/value               1 msg     : std_msgs/Float32         
/device_0/sensor_1/option/Brightness/description                     1 msg     : std_msgs/String          
/device_0/sensor_1/option/Brightness/value                           1 msg     : std_msgs/Float32         
/device_0/sensor_1/option/Contrast/description                       1 msg     : std_msgs/String          
/device_0/sensor_1/option/Contrast/value                             1 msg     : std_msgs/Float32         
/device_0/sensor_1/option/Enable_Auto_Exposure/description           1 msg     : std_msgs/String          
/device_0/sensor_1/option/Enable_Auto_Exposure/value                 1 msg     : std_msgs/Float32         
/device_0/sensor_1/option/Enable_Auto_White_Balance/description      1 msg     : std_msgs/String          
/device_0/sensor_1/option/Enable_Auto_White_Balance/value            1 msg     : std_msgs/Float32         
/device_0/sensor_1/option/Exposure/description                       1 msg     : std_msgs/String          
/device_0/sensor_1/option/Exposure/value                             1 msg     : std_msgs/Float32         
/device_0/sensor_1/option/Frames_Queue_Size/description              1 msg     : std_msgs/String          
/device_0/sensor_1/option/Frames_Queue_Size/value                    1 msg     : std_msgs/Float32         
/device_0/sensor_1/option/Gain/description                           1 msg     : std_msgs/String          
/device_0/sensor_1/option/Gain/value                                 1 msg     : std_msgs/Float32         
/device_0/sensor_1/option/Gamma/description                          1 msg     : std_msgs/String          
/device_0/sensor_1/option/Gamma/value                                1 msg     : std_msgs/Float32         
/device_0/sensor_1/option/Global_Time_Enabled/description            1 msg     : std_msgs/String          
/device_0/sensor_1/option/Global_Time_Enabled/value                  1 msg     : std_msgs/Float32         
/device_0/sensor_1/option/Hue/description                            1 msg     : std_msgs/String          
/device_0/sensor_1/option/Hue/value                                  1 msg     : std_msgs/Float32         
/device_0/sensor_1/option/Power_Line_Frequency/description           1 msg     : std_msgs/String          
/device_0/sensor_1/option/Power_Line_Frequency/value                 1 msg     : std_msgs/Float32         
/device_0/sensor_1/option/Saturation/description                     1 msg     : std_msgs/String          
/device_0/sensor_1/option/Saturation/value                           1 msg     : std_msgs/Float32         
/device_0/sensor_1/option/Sharpness/description                      1 msg     : std_msgs/String          
/device_0/sensor_1/option/Sharpness/value                            1 msg     : std_msgs/Float32         
/device_0/sensor_1/option/White_Balance/description                  1 msg     : std_msgs/String          
/device_0/sensor_1/option/White_Balance/value                        1 msg     : std_msgs/Float32         
/device_0/sensor_1/post_processing                                   1 msg     : std_msgs/String          
/file_version                                                        1 msg     : std_msgs/UInt32
real    0m0.220s
user    0m0.096s
sys     0m0.016s

Where I am making mistake? It seems it does not read the messages at all. I tried to run the code in terminal, I get the following error:

Traceback (most recent call last):
File "grab_rgb_bag.py", line 51, in <module>
for topic, msg, t in bag.read_messages(topics=[image_topic]):
File "/home/es/anaconda3/envs/hsi-env/lib/python3.8/site-packages/rosbag/bag.py", line 2705, in read_messages
yield self.seek_and_read_message_data_record((entry.chunk_pos, entry.offset), raw, return_connection_header)
File "/home/es/anaconda3/envs/hsi-env/lib/python3.8/site-packages/rosbag/bag.py", line 2839, in seek_and_read_message_data_record
raise ROSBagException('unsupported compression type: %s' % chunk_header.compression)
rosbag.bag.ROSBagException: unsupported compression type: lz4

答案1

得分: 1

首先尝试安装 lz4 支持:

apt install ros-$ROS_DISTRO-roslz4

如果这不起作用,请尝试使用 rosbag decompress 命令解压缩包,看看是否能够解析解压后的 rosbag。

参考链接:
http://wiki.ros.org/rosbag/Commandline#decompress

英文:

First try installing lz4 support:

apt install ros-$ROS_DISTRO-roslz4

If that does not work, try decompressing the bag using the rosbag decompress command, see if you are able to parse the decompressed rosbag.

See:
http://wiki.ros.org/rosbag/Commandline#decompress

huangapple
  • 本文由 发表于 2023年7月20日 13:09:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76726830.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定