User avatar
schoolpost
Posts: 164
Joined: Sun Feb 19, 2017 10:47 am
Location: Canada

Libcamera adjusting camera parameters live

Sun Sep 18, 2022 10:06 pm

Hello,

I'd like to be able to adjust camera parameters while the camera is running. I do not want to close the camera instance and reopen just to change the shutter speed for example. This is for a video application, so it would be quite annoying to the end user as they were adjusting the parameters to have the camera, start and stop constantly.

In libcamera-apps I've noted this method which passes camera parameters before starting the camera, but no subsequent method to do this after the camera is started and running:
https://github.com/raspberrypi/libcamer ... p.cpp#L445

Code: Select all

if (camera_->start(&controls_))
		throw std::runtime_error("failed to start camera");
such a method like this would be ideal for my application:

Code: Select all

camera_->update(&controls_)
where I could pass a ControlList to the camera.


In the previous version of my application/project the unicam driver exposed v4l2 controls, so it could be controlled outside the application context for example. Is this still possible?
-Csaba Nagy

therealdavidp
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 594
Joined: Tue Jan 07, 2020 9:15 am

Re: Libcamera adjusting camera parameters live

Mon Sep 19, 2022 8:22 am

In libcamera you pass control values like this by putting them into a request object before submitting it (see here, for example).

In libcamera-apps, however, we mostly hide the re-submitting of requests so instead we provide a SetControls method (here) which you can call at any time and it will schedule the controls to be sent as soon as possible.

User avatar
schoolpost
Posts: 164
Joined: Sun Feb 19, 2017 10:47 am
Location: Canada

Re: Libcamera adjusting camera parameters live

Mon Sep 19, 2022 8:45 am

therealdavidp wrote:
Mon Sep 19, 2022 8:22 am
In libcamera you pass control values like this by putting them into a request object before submitting it (see here, for example).

In libcamera-apps, however, we mostly hide the re-submitting of requests so instead we provide a SetControls method (here) which you can call at any time and it will schedule the controls to be sent as soon as possible.

Exactly what I was looking for, totally missed that! :?

Thanks :)
-Csaba Nagy

User avatar
schoolpost
Posts: 164
Joined: Sun Feb 19, 2017 10:47 am
Location: Canada

Re: Libcamera adjusting camera parameters live

Mon Sep 19, 2022 9:18 am

Hypothetically speaking, is there an alternate option for control? I'm guessing v4l2-ctl is out of the question as it probably locks access to the camera as it is being used in the libcamera-app?

I just tested the SetControls() method, which does exactly what it I want, although I do experience a decent amount of delay ( 1s ) between the controllist being summitted to the actual camera parameter changing.

Is there a way to speed up the request queue? is it slow because it is shared with requests for sensor frames?

Not an absolute dealbreaker, but I do know it was near instantaneous when I would control through my old unicam based app with v4l2-ctl
-Csaba Nagy

aBUGSworstnightmare
Posts: 5649
Joined: Tue Jun 30, 2015 1:35 pm

Re: Libcamera adjusting camera parameters live

Mon Sep 19, 2022 9:57 am

You're judging the time from the preview or how do you 'see' the 1s (or so) delay?

User avatar
schoolpost
Posts: 164
Joined: Sun Feb 19, 2017 10:47 am
Location: Canada

Re: Libcamera adjusting camera parameters live

Mon Sep 19, 2022 10:05 am

aBUGSworstnightmare wrote:
Mon Sep 19, 2022 9:57 am
You're judging the time from the preview or how do you 'see' the 1s (or so) delay?
Correct, the preview.
-Csaba Nagy

naushir
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 180
Joined: Mon Apr 25, 2016 10:21 am

Re: Libcamera adjusting camera parameters live

Mon Sep 19, 2022 12:08 pm

schoolpost wrote:
Mon Sep 19, 2022 9:18 am
Hypothetically speaking, is there an alternate option for control? I'm guessing v4l2-ctl is out of the question as it probably locks access to the camera as it is being used in the libcamera-app?

I just tested the SetControls() method, which does exactly what it I want, although I do experience a decent amount of delay ( 1s ) between the controllist being summitted to the actual camera parameter changing.

Is there a way to speed up the request queue? is it slow because it is shared with requests for sensor frames?

Not an absolute dealbreaker, but I do know it was near instantaneous when I would control through my old unicam based app with v4l2-ctl
There will be an inherent delay because of the number of requests already in-flight within the libcamera framework. Since the request with the control is put into the back of the queue, it will be actioned after a number of frames. There may also be additional delays of 1-3 frames if you are setting exposure time or analogue gain on the sensor, as they cannot be set instantaneously.

To "fix" this, you could possibly use a smaller number of requests, so the internal request queue is small. There is active discussions going on with the libcamera folks to somehow reduce this delay - possibly by having controls jump the request queue, but nothing has been concluded yet.

cpixip
Posts: 68
Joined: Mon May 01, 2017 7:56 am

Re: Libcamera adjusting camera parameters live

Thu Sep 22, 2022 3:09 pm

- you might be interested in this discussion (https://github.com/raspberrypi/picamera ... ssions/152) where a similar issue was discussed in the context of the alpha-release of picamera2.

Short summary: one seems to be able to get fast switches of exposure time with some tricks, but it usually takes about 11-12 frames until a specific exposure setting is "propagated" through the full pipeline. When working with 24fps, that is nearly half a second.

Also, libcamera seems to do some tricks with the digital gain in order to get a faster approach towards a requested exposure value. Basically, as setting the actual requested exposure time seems to need some time, occationally libcamera simulates for example an exposure time of 18928 as

Code: Select all

18928 = (DigitalGain = 2,0) * (ExposureTime =  9464)
for one or two frames. That is: the digital gain is used to compensate/adjust the requested exposure time. That is probably the reason why one can no longer set the digital gain in libcamera.

Return to “Camera board”