question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Setting manual focus does not always work.

See original GitHub issue

Describe the bug Manual focus setter does not always work.

With the exact same code and settings, sometimes the focus is set to the desired value (130) and sometimes to 0. The behavior seems to change more frequently if I disconnect and reconnect the device, or if I set/unset the autofocus. The behavior also changes when I leave the device inactive for some minutes.

I managed to reproduce this behavior with two different devices, connected to two different computers. I also tried to change the USB port.

Sometimes I also notice an abrupt change in focal length during the acquisition of the first frames, even though the autofocus is disabled and the manual focus is set to 130. After this abrupt change, the focus sets either to 0 or to the desired value.

To Reproduce I am currently using the following pipeline. At the end of it I set the autofocus to OFF and manual focus to 130.

pipeline = dai.Pipeline()

# RGB (center) Camera
center_camera = pipeline.createColorCamera()
center_camera.setPreviewSize(1280, 800)
center_camera.setBoardSocket(dai.CameraBoardSocket.RGB)
center_camera.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
center_camera.setInterleaved(True)
center_camera.setColorOrder(dai.ColorCameraProperties.ColorOrder.RGB)

# left camera
left_camera = pipeline.createMonoCamera()
left_camera.setResolution(dai.MonoCameraProperties.SensorResolution.THE_800_P)
left_camera.setBoardSocket(dai.CameraBoardSocket.LEFT)

# right camera
right_camera = pipeline.createMonoCamera()
right_camera.setResolution(dai.MonoCameraProperties.SensorResolution.THE_800_P)
right_camera.setBoardSocket(dai.CameraBoardSocket.RIGHT)

# center stream
center_stream = pipeline.createXLinkOut()
center_stream.setStreamName("center")
center_camera.preview.link(center_stream.input)

# left stream
left_stream = pipeline.createXLinkOut()
left_stream.setStreamName("left")
left_camera.out.link(left_stream.input)

# right stream
right_stream = pipeline.createXLinkOut()
right_stream.setStreamName("right")
right_camera.out.link(right_stream.input)

# camera control
cam_control_in = pipeline.createXLinkIn()
cam_control_in.setStreamName("cam_control")
cam_control_in.out.link(center_camera.inputControl)

# device
device = dai.Device(pipeline, usb2Mode=False)
device.startPipeline()
device.setLogLevel(dai.LogLevel.DEBUG)

# set focus
q_control = device.getInputQueue(name="cam_control")
cam_control = dai.CameraControl()
cam_control.setManualFocus(130)
cam_control.setAutoFocusMode(dai.RawCameraControl.AutoFocusMode.OFF)
q_control.send(cam_control)

Expected behavior Camera focus should be set to the same length every time I run the script.

Screenshots Running the script - this time it set the focus to 130. image

Running the exact same script again - this time the focus is wrong. image

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:7

github_iconTop GitHub Comments

2reactions
alex-luxoniscommented, Aug 4, 2021

We have a work-in-progress branch with a workaround for this issue: https://github.com/luxonis/depthai-python/pull/336 https://github.com/luxonis/depthai-core/pull/191

2reactions
LucaBonfigliolicommented, May 3, 2021

Yeah, we noticed that as well with autofocus initially enabled, sometimes it needs more than one set command to get to take effect. It’s some bug on the FW side.

For now, could you set manual focus initially at pipeline creation time, this should fix that behavior. Like:

center_camera.initialControl.setManualFocus(130)

# This may be redundant when setManualFocus is used
center_camera.initialControl.setAutoFocusMode(dai.RawCameraControl.AutoFocusMode.OFF) 

And if you want to set other types of controls at pipeline creation time, need to use the develop branch. We’ll probably make a release as well next week, to include it in main.

Using initialControl instead of “camControl” input queue seems to fix the issue. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Help! My New Manual Focus Lens Doesn't Work! EASY FIX
You've bought a new lens, but the camera won't release the shutter with the lens attached. Photographer Dustin Abbott explains how to ...
Read more >
My Camera Won't Focus: The 8 Most Common Problems
My Camera Won't Focus: The 8 Most Common Problems · 1. The Lens Needs to Be Calibrated · 2. Dirty AF Sensors ·...
Read more >
Nikon Autofocus Not Working? Try These 5 ...
1. Make sure you're using autofocus. It might seem silly, but it's surprisingly easy to accidentally set your equipment to focus manually instead...
Read more >
Auto focus AF trouble shooting – Why doesn't my camera ...
The first thing to check when your camera's auto focus fails, is that you have your DSLR lens set on AF (auto focus)...
Read more >
SOLVED: The auto focus doesn't work - Nikon D3200
If autofocus does not work even with a different lens, there's no easy fix - the problem is almost certainly with the camera...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found