From 00b3ca447a205ca4079e2dfd9c6cbe8e3faef04a Mon Sep 17 00:00:00 2001 From: Jerry Ylilammi Date: Fri, 26 Jan 2024 17:34:00 +0200 Subject: [PATCH 1/3] Support providing mxid to use specific OAKD device --- python/cli/record/oak.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/python/cli/record/oak.py b/python/cli/record/oak.py index d75eaae..e93ee4b 100644 --- a/python/cli/record/oak.py +++ b/python/cli/record/oak.py @@ -60,6 +60,8 @@ def define_args(p): p.add_argument("--resolution", help="Gray input resolution (gray)", default='400p', choices=['400p', '800p', '1200p']) + p.add_argument('--mxid', help="Specific OAK-D device's MxID you want to use, if you have multiple devices connected") + p.add_argument('--list_devices', help="List connected OAK-D devices", action="store_true") return p @@ -88,6 +90,10 @@ def record(args): import threading import time + if args.list_devices: + list_oakd_devices() + return + config = spectacularAI.depthai.Configuration() pipeline = depthai.Pipeline() @@ -173,7 +179,10 @@ def create_gray_encoder(node, name): def main_loop(plotter=None): frame_number = 1 - with depthai.Device(pipeline) as device, \ + deviceInfo = None + if args.mxid: deviceInfo = depthai.DeviceInfo(args.mxid) + + with depthai.Device(pipeline, deviceInfo) as device, \ vio_pipeline.startSession(device) as vio_session: if args.ir_dot_brightness > 0: From 6c669b1e0d3bff29685417cc58efa9767d793a2d Mon Sep 17 00:00:00 2001 From: Jerry Ylilammi Date: Fri, 26 Jan 2024 17:34:24 +0200 Subject: [PATCH 2/3] Fix depthai.Device constructor deprecation warnings --- python/cli/record/oak.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/python/cli/record/oak.py b/python/cli/record/oak.py index e93ee4b..dcf6207 100644 --- a/python/cli/record/oak.py +++ b/python/cli/record/oak.py @@ -81,6 +81,25 @@ def auto_subfolder(outputFolder): outputFolder = os.path.join(outputFolder, autoFolderName) return outputFolder +def list_oakd_devices(): + import depthai + print('Searching for all available devices...\n') + infos: List[depthai.DeviceInfo] = depthai.DeviceBootloader.getAllAvailableDevices() + if len(infos) == 0: + print("Couldn't find any available devices.") + return + for info in infos: + with depthai.Device(depthai.Pipeline(), info, depthai.UsbSpeed.SUPER_PLUS) as device: + calib = device.readCalibration() + eeprom = calib.getEepromData() + state = str(info.state).split('X_LINK_')[1] # Converts enum eg. 'XLinkDeviceState.X_LINK_UNBOOTED' to 'UNBOOTED' + print(f"Found device '{info.name}', MxId: '{info.mxid}'") + print(f" State: {state}") + print(f" Product name: {eeprom.productName}") + print(f" Board name: {eeprom.boardName}") + print(f" Camera sensors: {device.getCameraSensorNames()}") + + def record(args): import depthai import spectacularAI @@ -181,9 +200,12 @@ def main_loop(plotter=None): deviceInfo = None if args.mxid: deviceInfo = depthai.DeviceInfo(args.mxid) + def createDevice(): + if deviceInfo: + return depthai.Device(pipeline, deviceInfo=deviceInfo, maxUsbSpeed=depthai.UsbSpeed.SUPER_PLUS) + return depthai.Device(pipeline) - with depthai.Device(pipeline, deviceInfo) as device, \ - vio_pipeline.startSession(device) as vio_session: + with createDevice() as device, vio_pipeline.startSession(device) as vio_session: if args.ir_dot_brightness > 0: device.setIrLaserDotProjectorBrightness(args.ir_dot_brightness) From d9be1f026de6573077f7d7ce1f666646eaeee505 Mon Sep 17 00:00:00 2001 From: Jerry Ylilammi Date: Fri, 26 Jan 2024 17:35:05 +0200 Subject: [PATCH 3/3] Manual camera controls --- python/cli/record/oak.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/python/cli/record/oak.py b/python/cli/record/oak.py index dcf6207..7310aca 100644 --- a/python/cli/record/oak.py +++ b/python/cli/record/oak.py @@ -56,6 +56,9 @@ def define_args(p): p.add_argument('--map', help='Record SLAM map', action="store_true") p.add_argument('--no_feature_tracker', help='Disable on-device feature tracking', action="store_true") p.add_argument('--vio_auto_exposure', help='Enable SpectacularAI auto exposure which optimizes exposure parameters for VIO performance (BETA)', action="store_true") + p.add_argument('--white_balance', help='Set manual camera white balance temperature (K)', type=int) + p.add_argument('--exposure', help='Set manual camera exposure (us)', type=int) + p.add_argument('--sensitivity', help='Set camera sensitivity (iso)', type=int) p.add_argument('--ir_dot_brightness', help='OAK-D Pro (W) IR laser projector brightness (mA), 0 - 1200', type=float, default=0) p.add_argument("--resolution", help="Gray input resolution (gray)", default='400p', @@ -194,6 +197,19 @@ def create_gray_encoder(node, name): create_gray_encoder(vio_pipeline.stereo.rectifiedLeft, 'left') create_gray_encoder(vio_pipeline.stereo.rectifiedRight, 'right') + cameraControlQueueNames = [] + if args.white_balance or args.exposure or args.sensitivity: + def create_rgb_camera_control(colorCameraNode): + controlName = f"control_{len(cameraControlQueueNames)}" + cameraControlQueueNames.append(controlName) + controlIn = pipeline.create(depthai.node.XLinkIn) + controlIn.setStreamName(controlName) + controlIn.out.link(colorCameraNode.inputControl) + if vio_pipeline.colorLeft: create_rgb_camera_control(vio_pipeline.colorLeft) + if vio_pipeline.colorRight: create_rgb_camera_control(vio_pipeline.colorRight) + if vio_pipeline.monoLeft: create_rgb_camera_control(vio_pipeline.monoLeft) + if vio_pipeline.monoRight: create_rgb_camera_control(vio_pipeline.monoRight) + should_quit = threading.Event() def main_loop(plotter=None): frame_number = 1 @@ -226,6 +242,18 @@ def open_gray_video(name): videoFile = open(outputFolder + "/rgb_video.h265", "wb") rgbQueue = device.getOutputQueue(name="h265-rgb", maxSize=30, blocking=False) + if args.white_balance or args.exposure or args.sensitivity: + for controlName in cameraControlQueueNames: + cameraControlQueue = device.getInputQueue(name=controlName) + ctrl = depthai.CameraControl() + if args.exposure or args.sensitivity: + if not (args.exposure and args.sensitivity): + raise Exception("If exposure or sensitivity is given, then both of them must be given") + ctrl.setManualExposure(args.exposure, args.sensitivity) + if args.white_balance: + ctrl.setManualWhiteBalance(args.white_balance) + cameraControlQueue.send(ctrl) + print("Recording to '{0}'".format(config.recordingFolder)) print("") if plotter is not None: