Skip to content

Commit

Permalink
[RVC3] Added ability to set the lens position via a float, to enable …
Browse files Browse the repository at this point in the history
…a more precies movement. (#965)

* Added ability to set manual focus with a float. (gets you 10bit precision)

* Added lensPositionRaw to imgFrame

* Populate lens position on image frames

* Fix getLensPositionRaw in bindings

* Bump core

* Bump core

* Fix compilation

* clangformat

* Bump to develop
  • Loading branch information
zrezke authored Jun 11, 2024
1 parent ff92974 commit ba29193
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/pipeline/datatype/CameraControlBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ std::vector<const char *> camCtrlAttr;
.def_readwrite("cmdMask", &RawCameraControl::cmdMask)
.def_readwrite("autoFocusMode", &RawCameraControl::autoFocusMode)
.def_readwrite("lensPosition", &RawCameraControl::lensPosition)
.def_readwrite("lensPositionRaw", &RawCameraControl::lensPositionRaw)
.def_readwrite("expManual", &RawCameraControl::expManual)
.def_readwrite("afRegion", &RawCameraControl::afRegion)
.def_readwrite("awbMode", &RawCameraControl::awbMode)
Expand Down Expand Up @@ -196,6 +197,7 @@ std::vector<const char *> camCtrlAttr;
.def("setAutoFocusLensRange", &CameraControl::setAutoFocusLensRange, py::arg("infinityPosition"), py::arg("macroPosition"), DOC(dai, CameraControl, setAutoFocusLensRange))
.def("setAutoFocusRegion", &CameraControl::setAutoFocusRegion, py::arg("startX"), py::arg("startY"), py::arg("width"), py::arg("height"), DOC(dai, CameraControl, setAutoFocusRegion))
.def("setManualFocus", &CameraControl::setManualFocus, py::arg("lensPosition"), DOC(dai, CameraControl, setManualFocus))
.def("setManualFocusRaw", &CameraControl::setManualFocusRaw, py::arg("lensPosition"), DOC(dai, CameraControl, setManualFocusRaw))
.def("setAutoExposureEnable", &CameraControl::setAutoExposureEnable, DOC(dai, CameraControl, setAutoExposureEnable))
.def("setAutoExposureLock", &CameraControl::setAutoExposureLock, py::arg("lock"), DOC(dai, CameraControl, setAutoExposureLock))
.def("setAutoExposureRegion", &CameraControl::setAutoExposureRegion, py::arg("startX"), py::arg("startY"), py::arg("width"), py::arg("height"), DOC(dai, CameraControl, setAutoExposureRegion))
Expand Down Expand Up @@ -225,6 +227,7 @@ std::vector<const char *> camCtrlAttr;
.def("getExposureTime", &CameraControl::getExposureTime, DOC(dai, CameraControl, getExposureTime))
.def("getSensitivity", &CameraControl::getSensitivity, DOC(dai, CameraControl, getSensitivity))
.def("getLensPosition", &CameraControl::getLensPosition, DOC(dai, CameraControl, getLensPosition))
.def("getLensPositionRaw", &CameraControl::getLensPositionRaw, DOC(dai, CameraControl, getLensPositionRaw))
.def("get", &CameraControl::get, DOC(dai, CameraControl, get))
;
// Add also enum attributes from RawCameraControl
Expand Down
1 change: 1 addition & 0 deletions src/pipeline/datatype/ImgFrameBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ void bind_imgframe(pybind11::module& m, void* pCallstack){
.def("getSensitivity", &ImgFrame::getSensitivity, DOC(dai, ImgFrame, getSensitivity))
.def("getColorTemperature", &ImgFrame::getColorTemperature, DOC(dai, ImgFrame, getColorTemperature))
.def("getLensPosition", &ImgFrame::getLensPosition, DOC(dai, ImgFrame, getLensPosition))
.def("getLensPositionRaw", &ImgFrame::getLensPositionRaw, DOC(dai, ImgFrame, getLensPositionRaw))
.def("get", &ImgFrame::get, DOC(dai, ImgFrame, get))

// OpenCV Support section
Expand Down
10 changes: 5 additions & 5 deletions utilities/cam_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,16 @@ def get(self):
# Manual exposure/focus set step
EXP_STEP = 500 # us
ISO_STEP = 50
LENS_STEP = 3
LENS_STEP = 1 / 1024.0
DOT_STEP = 100
FLOOD_STEP = 100
DOT_MAX = 1200
FLOOD_MAX = 1500

# Defaults and limits for manual focus/exposure controls
lensPos = 150
lensMin = 0
lensMax = 255
lensPos = 0.5
lensMin = 0.0
lensMax = 1.0

expTime = 20000
expMin = 1
Expand Down Expand Up @@ -469,7 +469,7 @@ def get(self):
lensPos = clamp(lensPos, lensMin, lensMax)
print("Setting manual focus, lens position: ", lensPos)
ctrl = dai.CameraControl()
ctrl.setManualFocus(lensPos)
ctrl.setManualFocusRaw(lensPos)
controlQueue.send(ctrl)
elif key in [ord('i'), ord('o'), ord('k'), ord('l')]:
if key == ord('i'): expTime -= EXP_STEP
Expand Down

0 comments on commit ba29193

Please sign in to comment.