Datasets:

Modalities:
Image
Audio
Languages:
English
ArXiv:
License:
Yuan-Shenghai commited on
Commit
b00cd28
·
verified ·
1 Parent(s): d5aff06

Add V1/source_scripts/extract_radar.py

Browse files
Files changed (1) hide show
  1. V1/source_scripts/extract_radar.py +39 -0
V1/source_scripts/extract_radar.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import rospy
2
+ import numpy as np
3
+ from sensor_msgs.msg import PointCloud
4
+ import os
5
+ import rosbag
6
+ from tqdm import tqdm
7
+
8
+ def extract_radar_pointcloud_from_rosbag(bag_file, output_dir, radar_topic='/radar_enhanced_pcl', time_threshold=180.0):
9
+ rospy.init_node('extract_radar_pointcloud_from_rosbag', anonymous=True)
10
+
11
+ if not os.path.exists(output_dir):
12
+ os.makedirs(output_dir)
13
+
14
+ bag = rosbag.Bag(bag_file, 'r')
15
+
16
+
17
+ for topic, msg, t in tqdm(bag.read_messages(topics=[radar_topic]), desc='Extracting Radar Point Cloud'):
18
+ timestamp = msg.header.stamp.to_sec()
19
+
20
+ pointcloud_data = np.array([[-point.y, -point.z, point.x] for point in msg.points])
21
+
22
+ npy_filename = f"{timestamp:.6f}.npy"
23
+ npy_filepath = os.path.join(output_dir, npy_filename)
24
+ np.save(npy_filepath, pointcloud_data)
25
+
26
+
27
+ bag.close()
28
+
29
+
30
+
31
+ bag_list = os.listdir('bag/')
32
+
33
+ for name in bag_list:
34
+ bag_file_path = 'bag/'+name
35
+ save_dir = 'radar_enhance_pcl/'+name[:-4]
36
+
37
+ if not os.path.exists(save_dir):
38
+ os.makedirs(save_dir)
39
+ extract_radar_pointcloud_from_rosbag(bag_file_path, save_dir)