Skip to content

Commit

Permalink
IR intensity API (#920)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
zrezke authored Nov 23, 2023
1 parent 9c50aa6 commit 281c22f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
8 changes: 4 additions & 4 deletions examples/MonoCamera/mono_preview_alternate_pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())}')
Expand All @@ -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)
Expand Down
22 changes: 20 additions & 2 deletions src/DeviceBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
16 changes: 8 additions & 8 deletions utilities/cam_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'):
Expand Down

0 comments on commit 281c22f

Please sign in to comment.