1- #!/usr/bin/env python3
1+ import numpy as np
2+ import cv2
23
3- import depthai as dai
44from depthai_nodes .node import ApplyColormap
5- from utils .arguments import initialize_argparser
5+ import depthai as dai
6+
67from utils .dynamic_controler import DynamicCalibrationControler
7- import cv2
8- import numpy as np
9- print (dai .__file__ )
8+ from utils .arguments import initialize_argparser
9+
1010_ , args = initialize_argparser ()
1111
1212visualizer = dai .RemoteConnection (httpPort = 8082 )
13+ device = dai .Device (dai .DeviceInfo (args .device )) if args .device else dai .Device ()
1314# ---------- Pipeline definition ----------
14- pipeline = dai .Pipeline ()
15+ with dai .Pipeline (device ) as pipeline :
1516
16- # Create camera nodes
17- cam_left = pipeline .create (dai .node .Camera ).build (dai .CameraBoardSocket .CAM_B )
18- cam_right = pipeline .create (dai .node .Camera ).build (dai .CameraBoardSocket .CAM_C )
17+ # Create camera nodes
18+ cam_left = pipeline .create (dai .node .Camera ).build (dai .CameraBoardSocket .CAM_B )
19+ cam_right = pipeline .create (dai .node .Camera ).build (dai .CameraBoardSocket .CAM_C )
1920
20- # Request full resolution NV12 outputs
21- left_out = cam_left .requestFullResolutionOutput (dai .ImgFrame .Type .NV12 , fps = args .fps_limit )
22- right_out = cam_right .requestFullResolutionOutput (dai .ImgFrame .Type .NV12 , fps = args .fps_limit )
21+ # Request full resolution NV12 outputs
22+ left_out = cam_left .requestFullResolutionOutput (dai .ImgFrame .Type .NV12 , fps = args .fps_limit )
23+ right_out = cam_right .requestFullResolutionOutput (dai .ImgFrame .Type .NV12 , fps = args .fps_limit )
2324
24- # Stereo node
25- stereo = pipeline .create (dai .node .StereoDepth )
26- left_out .link (stereo .left )
27- right_out .link (stereo .right )
25+ # Stereo node
26+ stereo = pipeline .create (dai .node .StereoDepth )
27+ left_out .link (stereo .left )
28+ right_out .link (stereo .right )
2829
29- # Dynamic calibration node
30- dyn_calib = pipeline .create (dai .node .DynamicCalibration )
31- left_out .link (dyn_calib .left )
32- right_out .link (dyn_calib .right )
30+ # Dynamic calibration node
31+ dyn_calib = pipeline .create (dai .node .DynamicCalibration )
32+ left_out .link (dyn_calib .left )
33+ right_out .link (dyn_calib .right )
3334
34- # Output queues
35- depth_parser = pipeline .create (ApplyColormap ).build (stereo .disparity )
35+ # Output queues
36+ depth_parser = pipeline .create (ApplyColormap ).build (stereo .disparity )
3637 # depth_parser.setMaxValue(int(stereo.initialConfig.getMaxDisparity())) # NOTE: Uncomment when DAI fixes a bug
37- depth_parser .setColormap (cv2 .COLORMAP_JET )
38-
39- device = pipeline . getDefaultDevice ()
40-
41- calibration = device . readCalibration ()
42- new_calibration = None
43- old_calibration = None
44- # --- existing ---
45- calibration_output = dyn_calib .calibrationOutput .createOutputQueue ()
46- coverage_output = dyn_calib .coverageOutput .createOutputQueue ()
47- quality_output = dyn_calib .qualityOutput . createOutputQueue ()
48- input_control = dyn_calib . inputControl . createInputQueue ( )
49- device . setCalibration ( calibration )
50- # ---------- Visualizer setup ----------
51- visualizer .addTopic ("Left" , stereo .syncedLeft , "images" )
52- visualizer .addTopic ("Right" , stereo .syncedRight , "images" )
53- visualizer .addTopic ("Depth" , depth_parser .out , "images" )
54-
55- dyn_ctrl = pipeline .create (DynamicCalibrationControler ).build (
56- preview = depth_parser .out , # for timestamped overlays
57- depth = stereo .depth # raw uint16 depth in mm
58- )
59- visualizer .addTopic ("DynCalib HUD" , dyn_ctrl .out_annotations , "images" )
60-
61- pipeline .start ()
62- visualizer .registerPipeline (pipeline )
63-
64- # give it queues
65- dyn_ctrl .set_coverage_output (coverage_output )
66- dyn_ctrl .set_calibration_output (calibration_output )
67- dyn_ctrl .set_command_input (input_control )
68- dyn_ctrl .set_quality_output (quality_output )
69- dyn_ctrl .set_depth_units_is_mm (True ) # True for stereo.depth, False for disparity
70- dyn_ctrl .set_device (device )
71-
72- # (optional) seed current calibration
73- try :
74- dyn_ctrl .set_current_calibration (device .readCalibration ())
75- except Exception :
76- pass
77-
78- while pipeline .isRunning ():
79- key = visualizer .waitKey (1 )
80- if key != - 1 :
81- dyn_ctrl .handle_key_press (key )
82- if dyn_ctrl .wants_quit :
83- break
38+ depth_parser .setColormap (cv2 .COLORMAP_JET )
39+
40+ calibration = device . readCalibration ()
41+ new_calibration = None
42+ old_calibration = None
43+
44+ # --- existing ---
45+ calibration_output = dyn_calib . calibrationOutput . createOutputQueue ()
46+ coverage_output = dyn_calib .coverageOutput .createOutputQueue ()
47+ quality_output = dyn_calib .qualityOutput .createOutputQueue ()
48+ input_control = dyn_calib .inputControl . createInputQueue ()
49+ device . setCalibration ( calibration )
50+
51+ # ---------- Visualizer setup ----------
52+ visualizer .addTopic ("Left" , stereo .syncedLeft , "images" )
53+ visualizer .addTopic ("Right" , stereo .syncedRight , "images" )
54+ visualizer .addTopic ("Depth" , depth_parser .out , "images" )
55+
56+ dyn_ctrl = pipeline .create (DynamicCalibrationControler ).build (
57+ preview = depth_parser .out , # for timestamped overlays
58+ depth = stereo .depth # raw uint16 depth in mm
59+ )
60+ visualizer .addTopic ("DynCalib HUD" , dyn_ctrl .out_annotations , "images" )
61+
62+ pipeline .start ()
63+ visualizer .registerPipeline (pipeline )
64+
65+ # give it queues
66+ dyn_ctrl .set_coverage_output (coverage_output )
67+ dyn_ctrl .set_calibration_output (calibration_output )
68+ dyn_ctrl .set_command_input (input_control )
69+ dyn_ctrl .set_quality_output (quality_output )
70+ dyn_ctrl .set_depth_units_is_mm (True ) # True for stereo.depth, False for disparity
71+ dyn_ctrl .set_device (device )
72+
73+ # (optional) Set current calibration
74+ try :
75+ dyn_ctrl .set_current_calibration (device .readCalibration ())
76+ except Exception :
77+ pass
78+
79+ while pipeline .isRunning ():
80+ key = visualizer .waitKey (1 )
81+ if key != - 1 :
82+ dyn_ctrl .handle_key_press (key )
83+ if dyn_ctrl .wants_quit :
84+ break
0 commit comments