Skip to content

Commit bdb8cfe

Browse files
authored
Add option to use Python visualizer with sai-cli record oak (#37)
* Add option to use Python visualizer with sai-cli record oak * Clean code
1 parent 074bdde commit bdb8cfe

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

python/cli/record/oak.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def define_args(p):
4040
p.add_argument("--gray", help="Record (rectified) gray video data", action="store_true")
4141
p.add_argument("--no_convert", help="Skip converting h265 video file", action="store_true")
4242
p.add_argument('--no_preview', help='Do not show a live preview', action="store_true")
43+
p.add_argument('--preview3d', help='Use more advanced visualizer instead of matplotlib', action="store_true")
4344
p.add_argument('--no_slam', help='Record with SLAM module disabled', action="store_true")
4445
p.add_argument('--recording_only', help='Do not run VIO, may be faster', action="store_true")
4546
p.add_argument('--april_tag_path', help='Record with April Tags (path to tags.json)')
@@ -169,8 +170,27 @@ def record(args):
169170

170171
config.internalParameters = internalParameters
171172

173+
if args.no_preview:
174+
plotter = None
175+
visualizer = None
176+
elif args.preview3d:
177+
from spectacularAI.cli.visualization.visualizer import Visualizer, VisualizerArgs
178+
visArgs = VisualizerArgs()
179+
visArgs.targetFps = 30
180+
visualizer = Visualizer(visArgs)
181+
plotter = None
182+
config.parameterSets.append('point-cloud')
183+
else:
184+
from spectacularAI.cli.visualization.vio_visu import make_plotter
185+
import matplotlib.pyplot as plt
186+
plotter, anim = make_plotter()
187+
visualizer = None
188+
189+
def on_mapping_output(mapperOutput):
190+
visualizer.onMappingOutput(mapperOutput)
191+
172192
# Enable recoding by setting recordingFolder option
173-
vio_pipeline = spectacularAI.depthai.Pipeline(pipeline, config)
193+
vio_pipeline = spectacularAI.depthai.Pipeline(pipeline, config, None if visualizer is None else on_mapping_output)
174194

175195
# Optionally also record other video streams not used by the Spectacular AI SDK, these
176196
# can be used for example to render AR content or for debugging.
@@ -214,7 +234,7 @@ def create_rgb_camera_control(colorCameraNode):
214234
if vio_pipeline.monoRight: create_rgb_camera_control(vio_pipeline.monoRight)
215235

216236
should_quit = threading.Event()
217-
def main_loop(plotter=None):
237+
def main_loop(plotter=None, visualizer=None):
218238
frame_number = 1
219239

220240
deviceInfo = None
@@ -259,7 +279,7 @@ def open_gray_video(name):
259279

260280
print("Recording to '{0}'".format(config.recordingFolder))
261281
print("")
262-
if plotter is not None:
282+
if plotter is not None or visualizer is not None:
263283
print("Close the visualization window to stop recording")
264284

265285
while not should_quit.is_set():
@@ -280,6 +300,10 @@ def open_gray_video(name):
280300
if vio_session.hasOutput():
281301
out = vio_session.getOutput()
282302
progress = True
303+
304+
if visualizer is not None:
305+
visualizer.onVioOutput(out.getCameraPose(0), status=out.status)
306+
283307
if plotter is not None:
284308
if not plotter(json.loads(out.asJson())): break
285309

@@ -309,19 +333,15 @@ def open_gray_video(name):
309333
print("Use ffmpeg to convert video into a viewable format:")
310334
print(" " + ffmpegCommand)
311335

312-
if args.no_preview:
313-
plotter = None
314-
else:
315-
from spectacularAI.cli.visualization.vio_visu import make_plotter
316-
import matplotlib.pyplot as plt
317-
plotter, anim = make_plotter()
318-
319-
reader_thread = threading.Thread(target = lambda: main_loop(plotter))
336+
reader_thread = threading.Thread(target = lambda: main_loop(plotter, visualizer))
320337
reader_thread.start()
321-
if plotter is None:
322-
input("---- Press ENTER to stop recording ----")
323-
else:
338+
if visualizer is not None:
339+
visualizer.run()
340+
elif plotter is not None:
324341
plt.show()
342+
else:
343+
input("---- Press ENTER to stop recording ----")
344+
325345
should_quit.set()
326346

327347
reader_thread.join()

0 commit comments

Comments
 (0)