This repository was archived by the owner on Oct 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello_world.py
More file actions
executable file
·236 lines (180 loc) · 8.93 KB
/
Copy pathhello_world.py
File metadata and controls
executable file
·236 lines (180 loc) · 8.93 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/usr/bin/env python3
# ******************************************************************************
#
# Slamcore Confidential
# ---------------------
#
# Slamcore Limited
# All Rights Reserved.
# (C) Copyright 2023
#
# NOTICE:
#
# All information contained herein is, and remains the property of Slamcore
# Limited and its suppliers, if any. The intellectual and technical concepts
# contained herein are proprietary to Slamcore Limited and its suppliers and
# may be covered by patents in process, and are protected by trade secret or
# copyright law. Dissemination of this information or reproduction of this
# material is strictly forbidden unless prior written permission is obtained
# from Slamcore Limited.
#
# ******************************************************************************
import argparse
import datetime
import logging
import numpy as np
import slamcore
from pathlib import Path
def pose_callback(pose: slamcore.CameraPose):
print(f"Received: Pose\n\t {pose.translation}")
def smooth_pose_callback(pose: slamcore.CameraPose):
print(f"Received: SmoothPose\n\t {pose.translation}")
def slam_status_callback(status: slamcore.SLAMStatus):
print(f"Received: SLAMStatus\n\t {status.tracking_status}")
def video_callback(multi_frame: slamcore.MultiFrame):
kfStr = "KF" if multi_frame.is_keyframe else "NON-KF"
print(f"Received: MultiFrame\n\t {len(multi_frame)} {kfStr}")
for frame in multi_frame:
image = frame.image()
print(
f"\t\t{image.width} x {image.height} at {image.hw_timestamp.total_seconds()} [s]"
)
def imu_callback(imu_list: slamcore.IMUList):
print("Received: IMUList")
for measurement in imu_list:
print(f"\tTimestamp: {measurement.hw_timestamp.total_seconds()} [s]")
print(f"\t{measurement.sensor_id[0].name}: {measurement.measurement}")
def velocity_callback(velocity: slamcore.Velocity):
print("Received: Velocity")
print(f"\tLinear: {velocity.linear}\n\tAngular: {velocity.angular}")
def active_map_callback(active_map: slamcore.SparseMap):
print("Received: SparseMap")
print(f"\tLandmarks: {len(active_map)}")
def meta_data_callback(metadata: slamcore.MetaData):
print(f"Received: MetaData")
print(f"\t{metadata.id.name}: {metadata.value}")
def framesync_callback(_: slamcore.FrameSync):
print("Received: FrameSync")
def local_point_cloud_callback(point_cloud: slamcore.PointCloud):
print("Received: LocalPointCloud")
print(f"\tNumber of Points: {len(point_cloud)}")
def panoptic_bounding_box_callback(bbox_list: slamcore.PanopticBoundingBox3DList):
print("Received: PanopticBoundingBox3DList")
for bbox in bbox_list:
print(f"\tLabel: {bbox.label.name}")
print(f"\tInstance: {bbox.instance}")
print(f"\tSize: {bbox.bbox.size}")
print(f"\tLocation: {bbox.bbox.center_pose.translation}")
def panoptic_segmentation_result_callback(segmentation: slamcore.PanopticSegmentationResult):
print("Received: PanopticSegmentationResult")
print(f"\tLabels: {segmentation.pixel_labels.width} x {segmentation.pixel_labels.height}")
print(f"\tInstances: {segmentation.pixel_instances.width} x {segmentation.pixel_instances.height}")
def log_callback(msg: slamcore.logging.LogMessage):
severity_conversion = {
slamcore.logging.LogSeverity.Info: logging.INFO,
slamcore.logging.LogSeverity.Warning: logging.WARNING,
slamcore.logging.LogSeverity.Error: logging.ERROR,
slamcore.logging.LogSeverity.Fatal: logging.FATAL,
}
logging.log(severity_conversion[msg.severity], msg.message)
def main(dataset: Path, config: Path = None, enable_panoptic_plugin: bool = False) -> None:
slamcore.init(severity=slamcore.logging.LogSeverity.Info, callback=log_callback)
try:
cfg = slamcore.SystemConfiguration()
if dataset is not None:
cfg.sources.append(slamcore.DataSource.Dataset)
cfg.dataset_path = str(dataset)
else:
cfg.sources.append(slamcore.DataSource.AutoDetect)
if enable_panoptic_plugin:
cfg.sensor_enable_map = {
(slamcore.SensorType.Visible, 0) : True,
(slamcore.SensorType.Depth, 0) : True,
}
if config is not None:
cfg.config_file_path = str(config)
slam_system = slamcore.create_slam_system(cfg)
if slam_system is None:
logging.error("Failed to create SLAM system!")
exit(-1)
slam_system.open()
finished = False
logging.info(
f"Client Version: {slamcore.get_version()} / {slamcore.get_build_version()} / {slamcore.get_build_type()}"
)
logging.info(
f"SLAM Version: {slam_system.get_property(slamcore.Property.FirmwareVersion)} / {slam_system.get_property(slamcore.Property.FirmwareBuildVersion)} / {slam_system.get_property(slamcore.Property.FirmwareBuildType)}"
)
if slam_system.is_subsystem_supported(slamcore.subsystems.SensorsInfo):
sensors_info_subsystem = slam_system.get_sensor_info_subsystem()
for camera_sensor in sensors_info_subsystem.camera_list:
print(f"Camera: {camera_sensor}")
print(
f"\tSensor size: {sensors_info_subsystem.sensor_size(camera_sensor)}"
)
print(
f"\tImage format: {sensors_info_subsystem.image_format(camera_sensor)}"
)
if enable_panoptic_plugin:
subsystem = slam_system.get_panoptic_segmentation_subsystem()
subsystem.register_default_plugin()
label_mapping = subsystem.get_runner().label_mapping
for instance, panoptic_label in label_mapping.items():
type_str = 'Thing' if panoptic_label.isThing else 'Stuff'
print(f"{instance}: {panoptic_label.label.name} ({type_str})")
# Uncomment the following if you want to use low latency mode!
# slam_system.set_property(slamcore.Property.LowLatencyMode, True)
slam_system.set_stream_enabled(slamcore.Stream.Pose, True)
slam_system.set_stream_enabled(slamcore.Stream.SmoothPose, True)
slam_system.set_stream_enabled(slamcore.Stream.SLAMStatus, True)
slam_system.set_stream_enabled(slamcore.Stream.Video, True)
slam_system.set_stream_enabled(slamcore.Stream.IMU, True)
slam_system.set_stream_enabled(slamcore.Stream.ActiveMap, True)
slam_system.set_stream_enabled(slamcore.Stream.Velocity, True)
slam_system.set_stream_enabled(slamcore.Stream.MetaData, True)
slam_system.set_stream_enabled(slamcore.Stream.LocalPointCloud, True)
slam_system.set_stream_enabled(slamcore.Stream.ErrorCode, True)
slam_system.set_stream_enabled(slamcore.Stream.PanopticSegmentationResult, True)
slam_system.set_stream_enabled(slamcore.Stream.PanopticBoundingBox3D, True)
slam_system.register_pose_callback(pose_callback)
slam_system.register_smooth_pose_callback(smooth_pose_callback)
slam_system.register_slam_status_callback(slam_status_callback)
slam_system.register_video_callback(video_callback)
slam_system.register_imu_callback(imu_callback)
slam_system.register_active_map_callback(active_map_callback)
slam_system.register_velocity_callback(velocity_callback)
slam_system.register_meta_data_callback(meta_data_callback)
slam_system.register_local_point_cloud_callback(local_point_cloud_callback)
slam_system.register_panoptic_segmentation_result_callback(panoptic_segmentation_result_callback)
slam_system.register_panoptic_bounding_box_callback(panoptic_bounding_box_callback)
def error_callback(error: slamcore.ErrorCode):
eod_int = int(slamcore.errors.SystemErrorCode.ErrorValues.end_of_data)
if error.value.value == eod_int:
nonlocal finished
finished = True
slam_system.register_error_code_callback(error_callback)
slam_system.start()
while not finished:
try:
while slam_system.spin(datetime.timedelta(milliseconds=100)):
continue
else:
logging.warning("timeout")
except KeyboardInterrupt:
break
slam_system.stop()
slam_system.close()
print("We're Done Here.")
except Exception as ex:
logging.error(f"Exception caught: {ex}")
slamcore.deinit()
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
parser = argparse.ArgumentParser(
description="Example python script",
)
parser.add_argument("dataset", type=Path, nargs='?')
parser.add_argument("--config", type=Path, required=False)
parser.add_argument("--enable-panoptic-plugin", action="store_true", default=False)
args = parser.parse_args()
main(args.dataset, args.config, args.enable_panoptic_plugin)