This tutorial gets Autofocus working via command line using libcamera-still -t 3000 -o test.jpg --autofocus
But installing Picamera2 for Python causes this to break and then neither Picamera2 or libcamera work at that point.
What help do I need?
What I really need and the reason I bought this camera, is I need to be able to run this camera in 64-bit Raspberry Pi OS with the ability to use autofocus within a Python application in which I can also use OCR and Tesseract. The goal of my application is to be able to recognize license plates within a range of distances and then generate an audible alert when they are detected. The Autofocus is critical to this application as this is to be mounted on a helmet and to operate while a user is traveling down the street.
I have been trying for weeks to get this camera functioning with Autofocus within any kind of Python application in which I can generate a video, or still frames which I can then send to an OCR application or other object recognition utility to try and recognize. Can someone please provide some instruction of how to get this camera installed and operational with autofocus within Python on a 64-bit install of Raspberry Pi OS?
Some sample output
zero@raspberrypi:~/install/Arducam-Pivariety-V4L2-Driver/focus $ python3 FocuserExample.py
Traceback (most recent call last):
File "/home/trezero/install/Arducam-Pivariety-V4L2-Driver/focus/v4l2_utils.py", line 64, in get_device_controls_by_class
fcntl.ioctl(fd, v4l2.VIDIOC_QUERYCTRL, queryctrl)
OSError: [Errno 25] Inappropriate ioctl for device
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/trezero/install/Arducam-Pivariety-V4L2-Driver/focus/FocuserExample.py", line 157, in <module>
main()
File "/home/trezero/install/Arducam-Pivariety-V4L2-Driver/focus/FocuserExample.py", line 152, in main
focuser = Focuser(args.device)
File "/home/trezero/install/Arducam-Pivariety-V4L2-Driver/focus/Focuser.py", line 40, in __init__
self.ctrls = v4l2_utils.get_ctrls(self.fd)
File "/home/trezero/install/Arducam-Pivariety-V4L2-Driver/focus/v4l2_utils.py", line 96, in get_ctrls
for queryctrl in get_device_controls_by_class(vd, class_):
File "/home/trezero/install/Arducam-Pivariety-V4L2-Driver/focus/v4l2_utils.py", line 66, in get_device_controls_by_class
assert e.errno == errno.EINVAL
AssertionError
And another test
trezero@raspberrypi:~/install/Arducam-Pivariety-V4L2-Driver/focus $ libcamera-still -t 1000 -o test.jpg --autofocus
Made X/EGL preview window
[0:15:40.489214996] [1665] INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3730-67300b62
[0:15:40.498900250] [1667] WARN CameraSensorProperties camera_sensor_properties.cpp:174 No static properties available for 'imx519'
[0:15:40.499048428] [1667] WARN CameraSensorProperties camera_sensor_properties.cpp:176 Please consider updating the camera sensor properties database
[0:15:40.555630621] [1667] WARN RPI raspberrypi.cpp:1274 Mismatch between Unicam and CamHelper for embedded data usage!
[0:15:40.556914950] [1667] ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x009a090a but control is not exposed by device /dev/v4l-subdev0
[0:15:40.557294535] [1667] INFO RPI raspberrypi.cpp:1398 Registered camera /base/soc/i2c0mux/i2c@1/imx519@1a to Unicam device /dev/media3 and ISP device /dev/media0
[0:15:40.558873813] [1665] INFO Camera camera.cpp:1029 configuring streams: (0) 2048x1536-YUV420
[0:15:40.559774755] [1667] INFO RPI raspberrypi.cpp:763 Sensor: /base/soc/i2c0mux/i2c@1/imx519@1a - Selected sensor format: 2328x1748-SRGGB10_1X10 - Selected unicam format: 2328x1748-pRAA
Segmentation fault
# Automatically load overlays for detected cameras
camera_auto_detect=0
dtoverlay=imx519
At this point I can run libcamera-hello and see a live video (without any focus)
Then I do the following:
git clone https://github.com/ArduCAM/Arducam-Pivariety-V4L2-Driver.git
cd Arducam-Pivariety-V4L2-Driver/focus
python3 FocuserExample.py -d /dev/v4l-subdev0
And I get this result
trezero@raspberrypi:~/Arducam-Pivariety-V4L2-Driver/focus $ python3 FocuserExample.py -d /dev/v4l-subdev0
Traceback (most recent call last):
File "/home/trezero/Arducam-Pivariety-V4L2-Driver/focus/FocuserExample.py", line 157, in <module>
main()
File "/home/trezero/Arducam-Pivariety-V4L2-Driver/focus/FocuserExample.py", line 152, in main
focuser = Focuser(args.device)
File "/home/trezero/Arducam-Pivariety-V4L2-Driver/focus/Focuser.py", line 54, in __init__
raise RuntimeError("Device {} has no focus_absolute control.".format(self.dev))
RuntimeError: Device /dev/v4l-subdev0 has no focus_absolute control.
When I try this script without the AfTrigger it works. With it, I get a Segmentation Fault
#!/usr/bin/python3
from picamera2 import Picamera2
picam2 = Picamera2()
picam2.set_controls({"AfTrigger":0})
# Record a 5 second video.
picam2.start_and_record_video("test.mp4", duration=5)
Your configuration environment is correct, no changes are needed.
Your dependency has some conflicts.
This is because focus control is unique to us.
If you have python3-libcamera installed, this will cause you to use the official libcamera, which has no focus control.
trezero@raspberrypi:~ $ sudo apt remove python3-libcamera
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package 'python3-libcamera' is not installed, so not removed
The following packages were automatically installed and are no longer required:
freeglut3 libfuse2 libglu1-mesa libturbojpeg0 python3-opengl python3-pidng
python3-piexif python3-simplejpeg python3-v4l2
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.