From 281c22f9f6597321add30a7934732000065e1dfc Mon Sep 17 00:00:00 2001 From: Filip Jeretina <59307111+zrezke@users.noreply.github.com> Date: Thu, 23 Nov 2023 23:04:17 +0100 Subject: [PATCH] IR intensity API (#920) * Ir brightness control based on normalized intensity, instead of current. * Added IR intensity API. * Update docstring. Point to correct device side commit. * Bump core * Use IR intensity API in cam_test.py * Deprecated ir brightness api, fixed mono_preview_alternate_pro.py example * cam test: use step 0.05 for both dot projector and flood light * Update core * synced depthai-shared with device side * resolve shared issue. * Bump core --- depthai-core | 2 +- .../MonoCamera/mono_preview_alternate_pro.py | 8 +++---- src/DeviceBindings.cpp | 22 +++++++++++++++++-- utilities/cam_test.py | 16 +++++++------- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/depthai-core b/depthai-core index 22e513efc..6a10051bf 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 22e513efce56403053642ae5273afcf9400923c9 +Subproject commit 6a10051bf745fa8ff0ee900718649111e3c460e6 diff --git a/examples/MonoCamera/mono_preview_alternate_pro.py b/examples/MonoCamera/mono_preview_alternate_pro.py index 6f5997150..9d6e53800 100755 --- a/examples/MonoCamera/mono_preview_alternate_pro.py +++ b/examples/MonoCamera/mono_preview_alternate_pro.py @@ -43,8 +43,8 @@ script = pipeline.create(dai.node.Script) script.setProcessor(dai.ProcessorType.LEON_CSS) script.setScript(""" - dotBright = 500 # Note: recommended to not exceed 765, for max duty cycle - floodBright = 200 + dotBright = 0.8 + floodBright = 0.1 LOGGING = False # Set `True` for latency/timings debugging node.warn(f'IR drivers detected: {str(Device.getIrDrivers())}') @@ -57,8 +57,8 @@ # Immediately reconfigure the IR driver. # Note the logic is inverted, as it applies for next frame - Device.setIrLaserDotProjectorBrightness(0 if flagDot else dotBright) - Device.setIrFloodLightBrightness(floodBright if flagDot else 0) + Device.setIrLaserDotProjectorIntensity(0 if flagDot else dotBright) + Device.setIrFloodLightIntensity(floodBright if flagDot else 0) if LOGGING: tIrSet = Clock.now() # Wait for the actual frames (after MIPI capture and ISP proc is done) diff --git a/src/DeviceBindings.cpp b/src/DeviceBindings.cpp index add3b060b..f994e9022 100644 --- a/src/DeviceBindings.cpp +++ b/src/DeviceBindings.cpp @@ -636,8 +636,26 @@ void DeviceBindings::bind(pybind11::module& m, void* pCallstack){ .def("flashCalibration", [](DeviceBase& d, CalibrationHandler calibrationDataHandler) { py::gil_scoped_release release; return d.flashCalibration(calibrationDataHandler); }, py::arg("calibrationDataHandler"), DOC(dai, DeviceBase, flashCalibration)) .def("setXLinkChunkSize", [](DeviceBase& d, int s) { py::gil_scoped_release release; d.setXLinkChunkSize(s); }, py::arg("sizeBytes"), DOC(dai, DeviceBase, setXLinkChunkSize)) .def("getXLinkChunkSize", [](DeviceBase& d) { py::gil_scoped_release release; return d.getXLinkChunkSize(); }, DOC(dai, DeviceBase, getXLinkChunkSize)) - .def("setIrLaserDotProjectorBrightness", [](DeviceBase& d, float m, int mask) { py::gil_scoped_release release; return d.setIrLaserDotProjectorBrightness(m, mask); }, py::arg("mA"), py::arg("mask") = -1, DOC(dai, DeviceBase, setIrLaserDotProjectorBrightness)) - .def("setIrFloodLightBrightness", [](DeviceBase& d, float m, int mask) { py::gil_scoped_release release; return d.setIrFloodLightBrightness(m, mask); }, py::arg("mA"), py::arg("mask") = -1, DOC(dai, DeviceBase, setIrFloodLightBrightness)) + .def("setIrLaserDotProjectorBrightness", [](DeviceBase& d, float mA, int mask) { + PyErr_WarnEx(PyExc_DeprecationWarning, "Use setIrLaserDotProjectorIntensity() instead.", 1); + HEDLEY_DIAGNOSTIC_PUSH + HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED + py::gil_scoped_release release; + bool result = d.setIrLaserDotProjectorBrightness(mA, mask); + HEDLEY_DIAGNOSTIC_POP + return result; + }, py::arg("mA"), py::arg("mask") = -1, DOC(dai, DeviceBase, setIrLaserDotProjectorBrightness)) + .def("setIrFloodLightBrightness", [](DeviceBase& d, float mA, int mask) { + PyErr_WarnEx(PyExc_DeprecationWarning, "Use setIrFloodLightIntensity() instead.", 1); + HEDLEY_DIAGNOSTIC_PUSH + HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED + py::gil_scoped_release release; + bool result = d.setIrFloodLightBrightness(mA, mask); + HEDLEY_DIAGNOSTIC_POP + return result; + }, py::arg("mA"), py::arg("mask") = -1, DOC(dai, DeviceBase, setIrFloodLightBrightness)) + .def("setIrLaserDotProjectorIntensity", [](DeviceBase& d, float intensity, int mask) { py::gil_scoped_release release; return d.setIrLaserDotProjectorIntensity(intensity, mask); }, py::arg("intensity"), py::arg("mask") = -1, DOC(dai, DeviceBase, setIrLaserDotProjectorIntensity)) + .def("setIrFloodLightIntensity", [](DeviceBase& d, float intensity, int mask) { py::gil_scoped_release release; return d.setIrFloodLightIntensity(intensity, mask); }, py::arg("intensity"), py::arg("mask") = -1, DOC(dai, DeviceBase, setIrFloodLightIntensity)) .def("getIrDrivers", [](DeviceBase& d) { py::gil_scoped_release release; return d.getIrDrivers(); }, DOC(dai, DeviceBase, getIrDrivers)) .def("isEepromAvailable", [](DeviceBase& d) { py::gil_scoped_release release; return d.isEepromAvailable(); }, DOC(dai, DeviceBase, isEepromAvailable)) .def("flashCalibration2", [](DeviceBase& d, CalibrationHandler ch) { py::gil_scoped_release release; return d.flashCalibration2(ch); }, DOC(dai, DeviceBase, flashCalibration2)) diff --git a/utilities/cam_test.py b/utilities/cam_test.py index aaa55f882..aded6bdfa 100755 --- a/utilities/cam_test.py +++ b/utilities/cam_test.py @@ -354,10 +354,10 @@ def exit_cleanly(signum, frame): EXP_STEP = 500 # us ISO_STEP = 50 LENS_STEP = 3 - DOT_STEP = 100 - FLOOD_STEP = 100 - DOT_MAX = 1200 - FLOOD_MAX = 1500 + DOT_STEP = 0.05 + FLOOD_STEP = 0.05 + DOT_MAX = 1 + FLOOD_MAX = 1 # Defaults and limits for manual focus/exposure controls lensPos = 150 @@ -556,25 +556,25 @@ def exit_cleanly(signum, frame): dotIntensity = dotIntensity - DOT_STEP if dotIntensity < 0: dotIntensity = 0 - device.setIrLaserDotProjectorBrightness(dotIntensity) + device.setIrLaserDotProjectorIntensity(dotIntensity) print(f'IR Dot intensity:', dotIntensity) elif key == ord('d'): dotIntensity = dotIntensity + DOT_STEP if dotIntensity > DOT_MAX: dotIntensity = DOT_MAX - device.setIrLaserDotProjectorBrightness(dotIntensity) + device.setIrLaserDotProjectorIntensity(dotIntensity) print(f'IR Dot intensity:', dotIntensity) elif key == ord('w'): floodIntensity = floodIntensity + FLOOD_STEP if floodIntensity > FLOOD_MAX: floodIntensity = FLOOD_MAX - device.setIrFloodLightBrightness(floodIntensity) + device.setIrFloodLightIntensity(floodIntensity) print(f'IR Flood intensity:', floodIntensity) elif key == ord('s'): floodIntensity = floodIntensity - FLOOD_STEP if floodIntensity < 0: floodIntensity = 0 - device.setIrFloodLightBrightness(floodIntensity) + device.setIrFloodLightIntensity(floodIntensity) print(f'IR Flood intensity:', floodIntensity) elif key >= 0 and chr(key) in '34567890[]p\\;\'': if key == ord('3'):