How to use code to access libcamera(C++/Python)

hi

I suggest you to reinstall libcamera-dev.

Just tried to reinstall and it says :-
image

I did this :-

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

Which is in the manual.

I did fresh install and did eveything again and its working now.

Now my question is, once in Python and you run ā€œcam.set(libcamera.AfTrigger, 1)ā€ to auto focus.
how do you wait for the auto focus to finish before you can take a picture ?

hi, @Hosken79

You can achieve controllable autofocus and photography by responding to keyboard events.

What I want to do, is use the autofocus (as above) then once itā€™s focused on the person/object take a picture.
You canā€™t sent it to take a picture straight after as the autofocus is still adjusting, and adding a pause also doesnā€™t work.
How can I achieve this ? Any ideas ?

hi, @Hosken79

You can only take pictures after the autofocus is completed. There is no better idea at the moment.

So how do you detect that the autofocus has finished? Or is there no way to do this ATM ?

Hi,
Once the libcamera is initialized only set() can be seen. For one of the post where one link was shared shared for controls, is there any plans to share some some sort of query or get calls with the libcamera python package? Or is there anyway to query the camera properties once it is started with

cam.startcamera( )

Thanks.

Hi, @ac86074

We have implemented autofocus control on picamera2, all libcamera python libraries will still be out of maintenance.

Recently, we will release new versions of libcamera-dev and libcamera-apps packages.

You can choose to use picamera2. It is produced by Raspberry Pi, is fully functional and will be maintained for a long time.

Hi, Could you please show us how you have used Picamera2 with autofocus. Cheers

Hi, @jackzd

We will release the libcamera-dev and libcamera-apps packages for version 0.0.8 today.

At this time, you need to install the 0.0.8 version of libcamera-dev and the latest version of picamera2.

Then, set the AfTrigger to control the autofocus as you set the controls in the picamera2 example.

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

Thanks for that. Is there a way to control where the focus point is?

Hi, @jackzd

We implemented the program to control focus based on picamera2:

Hi there, I was wondering if you guys have managed to use this feature yet? I am trying to speed up the focus time, but when I try to implement this setting it just says it is not included in libcamera. Please see attached picture for reference to the libcamera setting I am wanting to implement.
AfSpeed

Hello @yang and the support team. Thank you for this thread. I was able to access libcamera using your demo C++ files, but I donā€™t see any command to tell the imx519 to autofocus using C++. Is there a set command I can send to it that tells it to autofocus, or is there code somewhere I can see how to make it autofocus?

IMO :

} else if (key == 'f') {
                controls_.set(controls::AfTrigger, 0);
                cam.set(controls_);
            }

This is supose to do the job ā€¦

https://libcamera.org/api-html/namespacelibcamera_1_1controls.html#a4e2c54ebb9dd200e458aea7632404f4a

Hi world,
Iā€™m creating my C++ app based on your libcamera_cpp_demo.

I have set generateConfiguration({ StreamRole::Viewfinder }) to StreamRole::Raw for speed purposes (the frame is 9152x6944-SBGGR10_1X10).

But controls_.set(controls::AfTrigger, 0) donā€™t works. ā€¦ any idea ?

More problems when trying to manually set focus :

controls_.set(controls::AfMode, controls::AfModeEnum::AfModeManual) donā€™t works
log = raspberrypi.cpp:1025 Ctrl AfMode is not handled.

controls_.set(controls::LensPosition, focusValue) donā€™t works too
log = raspberrypi.cpp:1025 Ctrl LensPosition is not handled.

More troubles when trying to use v4l2-ctl :
v4l2-ctl -l return nothing

v4l2-ctl -c focus_absolute=1 return ā€œunknown control ā€˜focus_absoluteā€™ā€

Any advice ?

Maybe there is an updated version of libcamera_cpp_demo ???
Thanks for your help.
Zeb.

Thanks for your opinion, actually Iā€™ve found a way to set the camera to auto-focus mode by adding this to the source code

controls_.set(controls::AfMode, 1);
controls_.set(controls::AfTrigger, 1);
cam.set(controls_);

ref = libcamera: libcamera::controls Namespace Reference

enum  	AfModeEnum { AfModeManual = 0, AfModeAuto = 1, AfModeContinuous = 2 }
enum  	AfTriggerEnum { AfTriggerStart = 0, AfTriggerCancel = 1 }

So your code should Cancel Af and not Start it ??!!!

Actually, the reason why I wrote

controls_.set(controls::AfTrigger, 1);

because I followed the previous answer from the author and it worked to set the camera to auto-focus mode
ref: How to use code to access libcamera(C++/Python) - #16 by yang
image