For my project, I need to lock focus on small objects at close range(30cm~150m). However, the current auto-focus keeps focusing on the background instead of the target, so I want to switch to manual focus control.
I tried the following code to disable auto-focus and manually set the focus value, but it does not seem to work. The camera still behaves like it is in auto-focus mode.
I would like to ask whether the OAK-4D-AF supports manual focus control on the RGB camera, especially when using the pipeline-based API in DepthAI 3.5.
Here is the code I used for testing:
import cv2
import depthai as dai
import threading
with dai.Pipeline() as pipeline:
camRgb = pipeline.create(dai.node.Camera)
camRgb.build(dai.CameraBoardSocket.CAM_A)
rgbOut = camRgb.requestOutput((640, 480), fps=10)
rgbQueue = rgbOut.createOutputQueue()
def focus_control_thread():
while True:
val = input("Enter focus value (0\~255), q to quit: ")
if val == 'q':
break
try:
focus = int(val)
focus = max(0, min(255, focus))
ctrl = dai.CameraControl()
ctrl.setManualFocus(focus)
camRgb.inputControl.send(ctrl)
print(f"Focus set to: {focus}")
except:
print("Please enter a valid integer")
pipeline.start()
threading.Thread(target=focus_control_thread, daemon=True).start()
print("Pipeline started")
while pipeline.isRunning():
rgbFrame = rgbQueue.get()
frame = rgbFrame.getCvFrame()
cv2.imshow("RGB", frame)
if cv2.waitKey(1) == ord('q'):
break
cv2.destroyAllWindows()