How to trigger single autofocus and wait till the camera focusses and check the status back, if focus success or failed?

When we trigger Aftirigger using the below code,

picam2.set_controls({"AfTrigger": 0})

How do you wait until the autofocus happens or know that image is focused or not?

@mullermuttu

There is currently no printout to tell you that autofocus is complete.
You can tell if autofocus is in progress by hearing the motor sound, or by seeing the motor moving.

At present, all source codes are public. If you need it, you can add some prints for judgment.

Another way is to open debug mode

export  LIBCAMERA_LOG_LEVELS=RPiAf:DEBUG

@Edward

Thanks for the reply,

For my application every time a capture button press happens I am triggering a focus and capture the image, after calling the trigger function I am calling the capture function

I am observing the below things,

  • image gets captured while still focusing happening.
  • don’t know how much time to wait before capture

like we picam2.wait() till the image captures, is there anything sort of this for aftrigger.

also what’s the usage of ‘Afstate’ can we use that in this case?

Please note that I am nor using libcamera commands, I am trying it on python using picamera2 package and libcamera drivers from arducam.

@mullermuttu

just a mind:

libcamera-apps “autofocus-on-capture” demo have achieved


You can take a look and develop with libcamera library

@Edward

I am looking for a Python solution since I do not have much experience in working with CPP.

Any help on this will be really grateful.

I just tried time.sleep(4) after calling aftrigger.

And sound that execution hangs for 4 second and then camera starts focusing.

Basically while waiting for 4 sec there was no focusing happening. Which defeats the purpose of using time.sleep.

@mullermuttu

Maybe you can try multithreading.

Let the sub-thread trigger autofocus, and save the picture after the sub-thread ends.