Hi everyone. I’m using the Arducam 12MP IMX477 Motorized Focus High Quality Camera on a Jetson Nano and I can’t get the autofocus to work at all. The sample code referenced in the documentation doesn’t run, and the docs don’t seem to cover the autofocus usage properly. Is there working code somewhere to record video with autofocus, or at least a script that can perform autofocus on its own? Any pointers would be really appreciated.
Thanks for the report. I checked into this and it looks like our documentation site was migrated recently, and the autofocus usage section didn’t carry over to the new site. That’s why you couldn’t find the working example in the docs. The code itself is still available in our GitHub repository, so nothing is lost - it’s just not linked properly from the new doc pages yet.
Good to know. Could you point me to the right repo path and the exact command to run? Also, is there a way to record video using that script, or would I need to write my own capture code around it?
Sure. The autofocus script is here: MIPI_Camera/Jetson/IMX477/AF_LENS at master · ArduCAM/MIPI_Camera · GitHub
Run it with:
python3 Autofocus.py -i 7
or
python3 Autofocus.py -i 8
(use 7 or 8 depending on which camera index your sensor shows up as).
For recording video, Autofocus.py is a good base - you’d need to modify it slightly to record while it focuses. It’s mostly a matter of adding the capture/encode part around the focus routine. Also, just to set expectations: this particular IMX477 motorized focus model is one of the most stable ones we’ve tested, so the hardware itself should be fine.
Thanks, the script runs now. But I’m seeing odd behavior: the autofocus only works for a short while after I start the script. If I change the distance of the subject, the camera never refocuses. I also noticed the GitHub code hasn’t been updated in about 2 years. Is this expected behavior for this camera, and if not, how can I fix it?
Could you share a bit more about your setup and how you’re launching it? Specifically: which board you’re using (I assume Jetson Nano based on the camera), the exact command, and any terminal output while it runs. Also, does it focus once at startup and then stop, or does it keep hunting after that?
Platform is a Jetson Nano. I’m using the AF_LENS code from GitHub and running python3 Autofocus.py -i 7. It focuses once when the script starts, then it doesn’t track anymore - after I move the subject, nothing happens until I restart the script. I recorded a short video of the behavior and sent it over in a private message. I don’t have any logs beyond the normal startup output.
Thanks for the video - that matches what you described. Based on the current AF_LENS script, it performs a one-shot focus sweep: it finds the sharpest position once and sets the lens there, then the script is effectively done. It doesn’t include a continuous/tracking autofocus mode, so it won’t refocus on its own when the subject distance changes. The repo is indeed older and hasn’t been updated, so this is currently a limitation of the example code rather than necessarily a hardware fault.
As a workaround, you can re-run the script to trigger a new focus, or modify the loop so it calls the focus routine again on demand or periodically. I can send you some pointers on where to hook that in via private message. We’re also checking whether a maintained or updated continuous-focus example is available. I’ll update this thread once I have more.