MCPcopy Create free account
hub / github.com/Thinklab-SJTU/Bench2Drive / visualize_data

Function visualize_data

tools/visualize.py:13–399  ·  view source on GitHub ↗
(file_path, map_path, vis_bbox=True,  vis_top_down=True, vis_road=True, vis_lidar_bev=True, vis_lidar_to_back_image=True, vis_lidar_to_front_image=True, vis_lidar_to_front_left_image=True)

Source from the content-addressed store, hash-verified

11from utils import get_image_point, point_in_canvas_wh, edges, world_to_ego, get_forward_vector, calculate_cube_vertices, draw_dashed_line, vector_angle, get_weather_id
12
13def visualize_data(file_path, map_path, vis_bbox=True, vis_top_down=True, vis_road=True, vis_lidar_bev=True, vis_lidar_to_back_image=True, vis_lidar_to_front_image=True, vis_lidar_to_front_left_image=True):
14 print(f'file_path={file_path}')
15 print(f'map_path={map_path}')
16
17 save_path = pathlib.Path(file_path.replace('v0','v0-vis'))
18 (save_path / 'camera' / 'rgb_front_3d_bbox').mkdir(parents=True, exist_ok=True)
19 (save_path / 'camera' / 'rgb_front_landmark').mkdir(parents=True, exist_ok=True)
20 (save_path / 'camera' / 'rgb_front_left_3d_bbox').mkdir(parents=True, exist_ok=True)
21 (save_path / 'camera' / 'rgb_front_right_3d_bbox').mkdir(parents=True, exist_ok=True)
22 (save_path / 'camera' / 'rgb_back_3d_bbox').mkdir(parents=True, exist_ok=True)
23 (save_path / 'camera' / 'rgb_back_left_3d_bbox').mkdir(parents=True, exist_ok=True)
24 (save_path / 'camera' / 'rgb_back_right_3d_bbox').mkdir(parents=True, exist_ok=True)
25 (save_path / 'camera' / 'rgb_top_down_3d_bbox').mkdir(parents=True, exist_ok=True)
26 (save_path / 'lidar' / 'bev').mkdir(parents=True, exist_ok=True)
27 (save_path / 'lidar' / 'front').mkdir(parents=True, exist_ok=True)
28 (save_path / 'lidar' / 'front_left').mkdir(parents=True, exist_ok=True)
29 (save_path / 'lidar' / 'back').mkdir(parents=True, exist_ok=True)
30
31 cam_map = {
32 'CAM_FRONT': 'rgb_front',
33 'CAM_FRONT_LEFT': 'rgb_front_left',
34 'CAM_FRONT_RIGHT': 'rgb_front_right',
35 'CAM_BACK': 'rgb_back',
36 'CAM_BACK_LEFT': 'rgb_back_left',
37 'CAM_BACK_RIGHT': 'rgb_back_right',
38 'TOP_DOWN': 'rgb_top_down'
39 }
40
41 folder_path = os.path.join(file_path, 'anno')
42 file_count = len([name for name in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, name))])
43 map_info = dict(np.load(map_path, allow_pickle=True)['arr'])
44
45 for step in trange(file_count):
46 with gzip.open(os.path.join(file_path, f'anno/{step:05}.json.gz'), 'rt', encoding='utf-8') as gz_file:
47 anno = json.load(gz_file)
48 weather_id = get_weather_id(anno['weather'])
49 bounding_boxes = anno['bounding_boxes']
50 sensors_anno = anno['sensors']
51 # ========================== bbox ==========================
52 if vis_bbox:
53 for key in ['CAM_FRONT','CAM_FRONT_LEFT','CAM_FRONT_RIGHT','CAM_BACK', 'CAM_BACK_LEFT', 'CAM_BACK_RIGHT']:
54 K = sensors_anno[key]['intrinsic']
55 world2cam = sensors_anno[key]['world2cam']
56 visulize_img = cv2.imread(os.path.join(file_path, f'camera/{cam_map[key]}/{step:05}.jpg'))
57 for npc in bounding_boxes:
58 if npc['class'] == 'ego_vehicle': continue
59 if npc['distance'] > 75: continue
60 if abs(npc['location'][2] - anno['bounding_boxes'][0]['location'][2]) > 10: continue # car in sky and underground
61 if 'vehicle' in npc['class']: # vehicle
62 forward_vec = get_forward_vector(sensors_anno[key]['rotation'][2])
63 ray = np.array(npc['location']) - np.array(sensors_anno[key]['location'])
64 color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
65 if forward_vec.dot(ray) > 1 and vector_angle(forward_vec, ray)<45:
66 verts = np.array(npc['world_cord'])
67 for edge in edges:
68 p1, p1_depth = get_image_point(verts[edge[0]], K, world2cam)
69 p2, p2_depth = get_image_point(verts[edge[1]], K, world2cam)
70 draw_dashed_line(visulize_img, (int(p1[0]),int(p1[1])), (int(p2[0]),int(p2[1])), color, 2)

Callers 1

visualize.pyFile · 0.85

Calls 8

get_weather_idFunction · 0.90
get_forward_vectorFunction · 0.90
vector_angleFunction · 0.90
get_image_pointFunction · 0.90
draw_dashed_lineFunction · 0.90
calculate_cube_verticesFunction · 0.90
point_in_canvas_whFunction · 0.90
world_to_egoFunction · 0.90

Tested by

no test coverage detected