forked from microsoft/lamar-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun_visualize_trajectories.py
More file actions
84 lines (69 loc) · 2.76 KB
/
run_visualize_trajectories.py
File metadata and controls
84 lines (69 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os
import argparse
from pathlib import Path
from scantools.capture import Capture
from scantools import logger
from scantools.viz.trajectories import (
visualize_trajectories
)
from scantools.utils.io import (
read_sequence_list
)
from scantools.utils.trajectory_pose_extraction import (
extract_pose_data
)
def run(
capture: Capture,
ios: bool = False,
hl: bool = False,
spot: bool = False
):
"""
Main function. Visualizes all trajectories of a given device and location.
"""
devices = []
if ios:
devices.append("ios")
if hl:
devices.append("hl")
if spot:
devices.append("spot")
capture_path = capture.path
clean_path = str(capture_path).rstrip('/')
location = os.path.basename(clean_path)
base_path = os.path.dirname(clean_path)
for device in devices:
logger.info(f"Visualizing trajectories for device: {device}")
if device == "hl":
suffix = "hololens"
elif device == "spot":
suffix = "spot"
elif device == "ios":
suffix = "phone"
# read all trajectories
session_ids = read_sequence_list(base_path / Path(location + "_" + suffix + ".txt"))
logger.info("Processing all files ...")
trajectories = []
for session_id in session_ids:
session_id = device + "_" + session_id
logger.info(f" Reading: {session_id}")
# get trajectory poses
trajectory = extract_pose_data(capture, session_id)
trajectories.append(trajectory)
logger.info(f" Done reading: {session_id}")
logger.info("Done processing.")
# visualize poses
save_path = capture.viz_path() / Path('trajectories') / Path(f"trajectories_{device}.png")
visualize_trajectories(trajectories=trajectories, save_path=save_path)
logger.info(f"Visualized trajectories for device {device}.")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Given prefix plots individual sessions together.")
parser.add_argument("--capture_path", type=Path, help="Capture path of the location to visualize trajectories.")
parser.add_argument("--ios", action="store_true", help="Enable ios trajectory visual")
parser.add_argument("--hl", action="store_true", help="Enable hl trajectory visual")
parser.add_argument("--spot", action="store_true", help="Enable spot trajectory visual")
args = parser.parse_args().__dict__
if args['ios'] is False and args['spot'] is False and args['hl'] is False:
parser.error("At least one of --ios, --hl, or --spot is required.")
args['capture'] = Capture.load(args.pop('capture_path'), session_ids=[])
run(**args)