Continuous autofocus libcamera-vid with 16mp imx519

Camera: 16MP Autofocus Camera for Raspberry Pi and Nvidia Jetson Nano/NX - Arducam
Device: Raspberry Pi 4 8gb
Linux version: the one recommended here: Setup IMX519 with any Raspberry Pi OS - #21 by Edward

If I do a

libcamera-vid --autofocus -t -0 --inline --listen -o tcp://0.0.0.0:8080 -n

And access this stream with something like

ffplay tcp://raspberrypi.local:8080 -f h264 -flags low_delay -probesize 32 -analyzeduration 0 -v error -an -x 640
0 -y 1024 -fast -vf "setpts=N/30"

Autofocus gets triggered at the first seconds of the video, and that’s it. It never updates focus again.

Is there a way to trigger the autofocus every now and then?

On a side note, how to trigger the autofocus manually? Say, when using openCV with libcamerify or with gstreamer?

@surak

You can try picamera2, we wrote a related program to control trigger auto focus.

tips: Prompt you need to install our libcamera first, we have recently upgraded, if you installed it a long time ago, you also need to upgrade

wget -O install_pivariety_pkgs.sh https://github.com/ArduCAM/Arducam-Pivariety-V4L2-Driver/releases/download/install_script/install_pivariety_pkgs.sh
chmod +x install_pivariety_pkgs.sh
./install_pivariety_pkgs.sh -p libcamera_dev
./install_pivariety_pkgs.sh -p libcamera_apps

I can’t make it work. I have the i2c enabled, and libcamera-hello --autofocus works - so the camera itself is fine and it can autofocus just fine.

The device seems to be there:

ls -la /dev/i2c*
crw-rw---- 1 root i2c 89,  0 Aug  7 17:11 /dev/i2c-0
crw-rw---- 1 root i2c 89,  1 Aug  7 17:11 /dev/i2c-1
crw-rw---- 1 root i2c 89, 10 Aug  7 17:11 /dev/i2c-10
crw-rw---- 1 root i2c 89, 20 Aug  7 17:11 /dev/i2c-20
crw-rw---- 1 root i2c 89, 21 Aug  7 17:11 /dev/i2c-21
crw-rw---- 1 root i2c 89, 22 Aug  7 17:11 /dev/i2c-22

This is what I see on the i2c detector:

$ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: 70 -- -- -- -- -- -- --                         

The user is part of the i2c unix group. No process is using any of the i2c files in /dev/, according to sudo lsof. Yet, when I try, I get this:

python ./AutofocusTest.py -i 10
[0:11:26.400553297] [2195]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3730-67300b62
[0:11:26.481037476] [2196]  WARN CameraSensorProperties camera_sensor_properties.cpp:174 No static properties available for 'imx519'
[0:11:26.481094161] [2196]  WARN CameraSensorProperties camera_sensor_properties.cpp:176 Please consider updating the camera sensor properties database
[0:11:26.497660628] [2196]  WARN RPI raspberrypi.cpp:1274 Mismatch between Unicam and CamHelper for embedded data usage!
[0:11:26.498322862] [2196] ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x009a090a but control is not exposed by device /dev/v4l-subdev0
[0:11:26.498492138] [2196]  INFO RPI raspberrypi.cpp:1398 Registered camera /base/soc/i2c0mux/[email protected]/[email protected] to Unicam device /dev/media3 and ISP device /dev/media0
[0:11:26.502039303] [2195]  INFO Camera camera.cpp:1029 configuring streams: (0) 640x360-XBGR8888
[0:11:26.502472465] [2196]  INFO RPI raspberrypi.cpp:763 Sensor: /base/soc/i2c0mux/[email protected]/[email protected] - Selected sensor format: 1280x720-SRGGB10_1X10 - Selected unicam format: 1280x720-pRAA
Error: Could not set address to 0x0c: Device or resource busy
Error: Could not set address to 0x0c: Device or resource busy
Error: Could not set address to 0x0c: Device or resource busy
Error: Could not set address to 0x0c: Device or resource busy

It’s the same with a normal user or with root, I always get resource busy.

I tried with all the /dev/ic2-XXX, none of them work.

@surak

okay,

You can follow the official example and write it yourself

Don’t wrong,the installed dependencies are enough to use the link I gave you before.

exposure control is:(This control is our modified)

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

Great, so this work! Where can I find documentation about this api?

I think it’s important to notice that I am using the recommended Bullseye 64 bit version of Raspberry OS.

So, NO code from the https://github.com/ArduCAM/RaspberryPi repository work:

  1. the C code contains a 32-bit only binary file which can’t be used anymore.
  2. the python code just doesn’t work, no matter which i2c port you use.

On the positive side:

Perhaps one could do a good cleanup of the different repos and make things work in both 32 and 64 bit.

Thanks for the great work!

@surak

picamera2 we only added a focus interface, the rest is highly consistent with the official.

You can follow the official api to the letter.