Arducam 64MP Hawkeye autofocus not working with OpenCV and GStreamer on Raspberry Pi 5

Hi everyone, I’m stuck with my Arducam 64MP Hawkeye camera. Autofocus simply won’t work when I open the camera through OpenCV with a GStreamer pipeline. The image comes up but it just never focuses. Has anyone run into this?

Sorry you’re hitting that. Can you share a bit more about your setup? Which board are you using, exact camera model, and how are you initializing the camera in OpenCV/GStreamer?

Sure. I’m on a Raspberry Pi 5 with the Arducam 64MP Hawkeye Camera. I followed the docs at 64MP Hawkeye - Arducam Wiki to set it up. I’ve also attached my test script gpTest.py (https://cdn.arducam.com/forum/e3c84accb4b8a8e98f6382e087660260/gpTest.py) so you can see what I’m doing. The weird part is the camera works fine with the libcamera library.

Just to make sure I understand the symptom: with libcamera-still the autofocus works correctly, but when you go through OpenCV + GStreamer it doesn’t focus at all? Are all the dependencies installed and the camera connection confirmed?

Exactly. libcamera-still focuses perfectly every time, so I’m pretty sure the hardware connection and wiring are fine. All dependencies are properly configured too. It’s only the OpenCV + GStreamer path where autofocus does nothing.

I’m Dion, taking a look at this. I reviewed your gpTest.py. I’ve attached a reference Python file to this thread for you to use as a starting point, but please note it can only focus objects at a short distance, so it will need modification. The underlying problem is that the OpenCV/GStreamer pipeline is not applying or enabling the Arducam autofocus configuration, so you can’t rely on the default GStreamer behavior to handle focusing.

Thanks for the reference file. I tried it and it does focus now, but only when the object is close. Anything at a longer distance stays blurry. How do I extend the focusing range?

Right, that matches what we saw. Since autofocus works under libcamera/libcamera-still, the hardware itself is fine — this is specific to the OpenCV/GStreamer software path. What you need to do is use the attached Python file as a reference and modify it, enabling and configuring the Arducam autofocus inside your Python OpenCV code rather than depending on the default GStreamer pipeline.

Got it, so I need to handle the autofocus configuration directly in my OpenCV script instead of expecting GStreamer to do it. I’ll start from your reference file and adjust it for longer distance focusing. Thanks for the pointer.

To wrap this up: autofocus works with libcamera-still, which confirms the camera is connected correctly, so the issue is only in the OpenCV + GStreamer software path. The reference Python file I attached is not a complete solution — it only focuses at short distances — so use it as a base, modify it to improve the focusing distance, and apply the autofocus configuration within your OpenCV + GStreamer pipeline on the Raspberry Pi 5. Let us know how it behaves after you adjust it.