Skip to content

Commit 62a8c44

Browse files
committed
feat(check_flow): visualize it easily with a inside func.
1 parent 348fa1e commit 62a8c44

2 files changed

Lines changed: 55 additions & 28 deletions

File tree

scripts/utils/mics.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -276,34 +276,23 @@ def __getitem__(self, index):
276276
scene_id, timestamp = self.data_index[index]
277277

278278
key = str(timestamp)
279+
data_dict = {
280+
'scene_id': scene_id,
281+
'timestamp': timestamp,
282+
}
279283
with h5py.File(os.path.join(self.directory, f'{scene_id}.h5'), 'r') as f:
280284
# original data
281-
pc0 = f[key]['lidar'][:]
282-
gm0 = f[key]['ground_mask'][:]
283-
pose0 = f[key]['pose'][:]
284-
285-
label = None
286-
if 'label' in f[key]:
287-
label = f[key]['label'][:]
285+
data_dict['pc0'] = f[key]['lidar'][:]
286+
data_dict['gm0'] = f[key]['ground_mask'][:]
287+
data_dict['pose0'] = f[key]['pose'][:]
288288

289289
if self.flow_view:
290-
flow = f[key][self.vis_name][:]
290+
data_dict[self.vis_name] = f[key][self.vis_name][:]
291291
next_timestamp = str(self.data_index[index+1][1])
292-
pose1 = f[next_timestamp]['pose'][:]
293-
294-
data_dict = {
295-
'scene_id': scene_id,
296-
'timestamp': timestamp,
297-
'pc0': pc0,
298-
'gm0': gm0,
299-
'pose0': pose0,
300-
'label': label,
301-
}
302-
303-
if self.flow_view:
304-
data_dict[self.vis_name] = flow
305-
data_dict['pose1'] = pose1
306-
292+
data_dict['pose1'] = f[next_timestamp]['pose'][:]
293+
data_dict['pc1'] = f[next_timestamp]['lidar'][:]
294+
data_dict['gm1'] = f[next_timestamp]['ground_mask'][:]
295+
307296
return data_dict
308297

309298
from av2.geometry.se3 import SE3

tests/scene_flow.py

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
# Created: 2023-11-29 21:22
33
# Copyright (C) 2023-now, RPL, KTH Royal Institute of Technology
4-
# Author: Kin ZHANG (https://kin-zhang.github.io/)
4+
# Author: Qingwen Zhang (https://kin-zhang.github.io/)
55
#
66
# This work is licensed under the terms of the MIT license.
77
# For a copy, see <https://opensource.org/licenses/MIT>.
@@ -22,6 +22,44 @@
2222

2323
VIEW_FILE = f"{BASE_DIR}/assets/view/av2.json"
2424

25+
def check_flow(
26+
data_dir: str ="/home/kin/data/av2/preprocess/sensor/mini",
27+
flow_mode: str = "flow", # "flow", "flow_est"
28+
start_id: int = -1,
29+
point_size: float = 3.0,
30+
):
31+
dataset = HDF5Data(data_dir, vis_name=flow_mode, flow_view=True)
32+
o3d_vis = MyVisualizer(view_file=VIEW_FILE, window_title=f"view {'ground truth flow' if flow_mode == 'flow' else f'{flow_mode} flow'}, `SPACE` start/stop")
33+
34+
opt = o3d_vis.vis.get_render_option()
35+
opt.background_color = np.asarray([80/255, 90/255, 110/255])
36+
opt.point_size = point_size
37+
38+
for data_id in (pbar := tqdm(range(0, len(dataset)))):
39+
# for easy stop and jump to any id, and save same id always from 0.
40+
if data_id < start_id and start_id != -1:
41+
continue
42+
data = dataset[data_id]
43+
now_scene_id = data['scene_id']
44+
pbar.set_description(f"id: {data_id}, scene_id: {now_scene_id}, timestamp: {data['timestamp']}")
45+
gm0 = data['gm0']
46+
pc0 = data['pc0'][~gm0]
47+
48+
pcd = o3d.geometry.PointCloud()
49+
pcd.points = o3d.utility.Vector3dVector(pc0[:, :3])
50+
pcd.paint_uniform_color([1.0, 0.0, 0.0]) # red: pc0
51+
52+
pc1 = data['pc1']
53+
pcd1 = o3d.geometry.PointCloud()
54+
pcd1.points = o3d.utility.Vector3dVector(pc1[:, :3][~data['gm1']])
55+
pcd1.paint_uniform_color([0.0, 1.0, 0.0]) # green: pc1
56+
57+
pcd2 = o3d.geometry.PointCloud()
58+
# pcd2.points = o3d.utility.Vector3dVector(pc0[:, :3] + pose_flow) # if you want to check pose_flow
59+
pcd2.points = o3d.utility.Vector3dVector(pc0[:, :3] + data[flow_mode][~gm0])
60+
pcd2.paint_uniform_color([0.0, 0.0, 1.0]) # blue: pc0 + flow
61+
o3d_vis.update([pcd, pcd1, pcd2, o3d.geometry.TriangleMesh.create_coordinate_frame(size=2)])
62+
2563
def vis(
2664
data_dir: str ="/home/kin/data/av2/preprocess/sensor/mini",
2765
flow_mode: str = "flow", # "flow", "flow_est"
@@ -38,14 +76,13 @@ def vis(
3876
opt.point_size = point_size
3977

4078
for data_id in (pbar := tqdm(range(0, len(dataset)))):
79+
# for easy stop and jump to any id, and save same id always from 0.
80+
if data_id < start_id and start_id != -1:
81+
continue
4182
data = dataset[data_id]
4283
now_scene_id = data['scene_id']
4384
pbar.set_description(f"id: {data_id}, scene_id: {now_scene_id}, timestamp: {data['timestamp']}")
4485

45-
# for easy stop and jump to any id
46-
if data_id < start_id and start_id != -1:
47-
continue
48-
4986
pc0 = data['pc0']
5087
gm0 = data['gm0']
5188
pose0 = data['pose0']
@@ -69,5 +106,6 @@ def vis(
69106

70107
if __name__ == '__main__':
71108
start_time = time.time()
109+
# fire.Fire(check_flow)
72110
fire.Fire(vis)
73111
print(f"Time used: {time.time() - start_time:.2f} s")

0 commit comments

Comments
 (0)