[libcamera-devel,RFC,0/4] Introduce camera lens properties
mbox series

Message ID 20220609060306.57953-1-jeanmichel.hautbois@ideasonboard.com
Headers show
Series
  • Introduce camera lens properties
Related show

Message

Jean-Michel Hautbois June 9, 2022, 6:03 a.m. UTC
This series introduces a camera lens properties database in the same way
we have a camera sensor properties one. The idea is to be able to
provide to the pipeline handler (and thus, the IPAs) any useful property
defining a tuned lens.

This series is a RFC as it is not really clear, for instance, which
properties may be useful (a macroRange and a FullRange sound like
something useful for instance ?) and which units should be used for
hyperfocale.

I don't have a tuned sensor (and indeed, I really wish I could have a
way to tune it properly :-)) so the values here must be used as examples
only.

Patch 3/4 is a specific property, in order to address one of the
AfControls series "todo".

Currently, we may use a range as large as the one reported by the
V4L2_CID_FOCUS_ABSOLUTE call, but all may not be valid.
For instance, some drivers can set 10 bits values, but only the first 9
are relevant, as the macro mode is limited by the lens properties.
We may want to have multiple ranges in a near future (macro, full,
limited ?) and for the ease the range is returned as a libcamera::Size
object, as I don't really know what would be better yet ;-).

Patch 4/4 is the hyperfocale value, expressed in millimeters. Is it the
correct unit is a question too :-).

Thanks !
JM

Jean-Michel Hautbois (4):
  libcamera: Add a camera lens properties database
  libcamera: lens: Grab the static properties at init time
  libcamera: lens: Add a helper to get the fixed range lens values
  libcamera: lens: Add the hyperfocale property support

 include/libcamera/internal/camera_lens.h      |  5 ++
 .../internal/camera_lens_properties.h         | 25 +++++++
 src/libcamera/camera_lens.cpp                 | 24 ++++++-
 src/libcamera/camera_lens_properties.cpp      | 70 +++++++++++++++++++
 src/libcamera/meson.build                     |  1 +
 5 files changed, 124 insertions(+), 1 deletion(-)
 create mode 100644 include/libcamera/internal/camera_lens_properties.h
 create mode 100644 src/libcamera/camera_lens_properties.cpp

Comments

Laurent Pinchart June 9, 2022, 9:33 a.m. UTC | #1
Hi Jean-Michel,

Thank you for the patch.

On Thu, Jun 09, 2022 at 08:03:02AM +0200, Jean-Michel Hautbois via libcamera-devel wrote:
> This series introduces a camera lens properties database in the same way
> we have a camera sensor properties one. The idea is to be able to
> provide to the pipeline handler (and thus, the IPAs) any useful property
> defining a tuned lens.

Could you explain the rationale behind this ? How do you plan to index
that database ?

> This series is a RFC as it is not really clear, for instance, which
> properties may be useful (a macroRange and a FullRange sound like
> something useful for instance ?) and which units should be used for
> hyperfocale.
> 
> I don't have a tuned sensor (and indeed, I really wish I could have a
> way to tune it properly :-)) so the values here must be used as examples
> only.
> 
> Patch 3/4 is a specific property, in order to address one of the
> AfControls series "todo".
> 
> Currently, we may use a range as large as the one reported by the
> V4L2_CID_FOCUS_ABSOLUTE call, but all may not be valid.
> For instance, some drivers can set 10 bits values, but only the first 9
> are relevant, as the macro mode is limited by the lens properties.
> We may want to have multiple ranges in a near future (macro, full,
> limited ?) and for the ease the range is returned as a libcamera::Size
> object, as I don't really know what would be better yet ;-).
> 
> Patch 4/4 is the hyperfocale value, expressed in millimeters. Is it the
> correct unit is a question too :-).
> 
> Thanks !
> JM
> 
> Jean-Michel Hautbois (4):
>   libcamera: Add a camera lens properties database
>   libcamera: lens: Grab the static properties at init time
>   libcamera: lens: Add a helper to get the fixed range lens values
>   libcamera: lens: Add the hyperfocale property support
> 
>  include/libcamera/internal/camera_lens.h      |  5 ++
>  .../internal/camera_lens_properties.h         | 25 +++++++
>  src/libcamera/camera_lens.cpp                 | 24 ++++++-
>  src/libcamera/camera_lens_properties.cpp      | 70 +++++++++++++++++++
>  src/libcamera/meson.build                     |  1 +
>  5 files changed, 124 insertions(+), 1 deletion(-)
>  create mode 100644 include/libcamera/internal/camera_lens_properties.h
>  create mode 100644 src/libcamera/camera_lens_properties.cpp
Jean-Michel Hautbois June 13, 2022, 3:57 p.m. UTC | #2
Hi Laurent,

On 09/06/2022 11:33, Laurent Pinchart wrote:
> Hi Jean-Michel,
> 
> Thank you for the patch.
> 
> On Thu, Jun 09, 2022 at 08:03:02AM +0200, Jean-Michel Hautbois via libcamera-devel wrote:
>> This series introduces a camera lens properties database in the same way
>> we have a camera sensor properties one. The idea is to be able to
>> provide to the pipeline handler (and thus, the IPAs) any useful property
>> defining a tuned lens.
> 
> Could you explain the rationale behind this ? How do you plan to index
> that database ?
> 

Let me try to write it down, adding David and Naushir in cc :-).

Let's take the LensPosition control in the autofocus. This control can 
be set by the user in the AfModeManual but it should also be reported 
for each frame in the metadata.

This value is not the VCM value, but a normalized distance based on the 
hyperfocale. To be able, from the AF algorithm, to fill the value (or to 
set it) the hyperfocale value needs to be known for the lens used.

Right now, we have a CameraLens class, which controls the VCM driver. 
But a lens is not only the VCM, but a couple sensor/VCM mounted in a 
module. I found this page to be interesting to have a high level 
understanding btw [1].

The issue, right now, is that we don't have anything else than the 
sensor driver model, or the vcm model, nothing else, so we can't 
automatically find the lens tuning parameters in a file or a cpp structure.

[1]: https://www.arducam.com/focal-length-calculator/

This is why, with a RFC tag, I tried something based on the VCM model. 
But after some discussions, it looks like it is not solving it at all, 
and a better way will be to have a tuning file, set by the userspace.

Now, it makes me wonder: how can we send a LensPosition in a 
non-calibrated lens case ?

Thanks !
JM
PS: this series will obviously be dropped ;-).

>> This series is a RFC as it is not really clear, for instance, which
>> properties may be useful (a macroRange and a FullRange sound like
>> something useful for instance ?) and which units should be used for
>> hyperfocale.
>>
>> I don't have a tuned sensor (and indeed, I really wish I could have a
>> way to tune it properly :-)) so the values here must be used as examples
>> only.
>>
>> Patch 3/4 is a specific property, in order to address one of the
>> AfControls series "todo".
>>
>> Currently, we may use a range as large as the one reported by the
>> V4L2_CID_FOCUS_ABSOLUTE call, but all may not be valid.
>> For instance, some drivers can set 10 bits values, but only the first 9
>> are relevant, as the macro mode is limited by the lens properties.
>> We may want to have multiple ranges in a near future (macro, full,
>> limited ?) and for the ease the range is returned as a libcamera::Size
>> object, as I don't really know what would be better yet ;-).
>>
>> Patch 4/4 is the hyperfocale value, expressed in millimeters. Is it the
>> correct unit is a question too :-).
>>
>> Thanks !
>> JM
>>
>> Jean-Michel Hautbois (4):
>>    libcamera: Add a camera lens properties database
>>    libcamera: lens: Grab the static properties at init time
>>    libcamera: lens: Add a helper to get the fixed range lens values
>>    libcamera: lens: Add the hyperfocale property support
>>
>>   include/libcamera/internal/camera_lens.h      |  5 ++
>>   .../internal/camera_lens_properties.h         | 25 +++++++
>>   src/libcamera/camera_lens.cpp                 | 24 ++++++-
>>   src/libcamera/camera_lens_properties.cpp      | 70 +++++++++++++++++++
>>   src/libcamera/meson.build                     |  1 +
>>   5 files changed, 124 insertions(+), 1 deletion(-)
>>   create mode 100644 include/libcamera/internal/camera_lens_properties.h
>>   create mode 100644 src/libcamera/camera_lens_properties.cpp
>
Laurent Pinchart June 14, 2022, 11:43 a.m. UTC | #3
Hi Jean-Michel,

On Mon, Jun 13, 2022 at 05:57:19PM +0200, Jean-Michel Hautbois wrote:
> On 09/06/2022 11:33, Laurent Pinchart wrote:
> > On Thu, Jun 09, 2022 at 08:03:02AM +0200, Jean-Michel Hautbois via libcamera-devel wrote:
> >> This series introduces a camera lens properties database in the same way
> >> we have a camera sensor properties one. The idea is to be able to
> >> provide to the pipeline handler (and thus, the IPAs) any useful property
> >> defining a tuned lens.
> > 
> > Could you explain the rationale behind this ? How do you plan to index
> > that database ?
> 
> Let me try to write it down, adding David and Naushir in cc :-).
> 
> Let's take the LensPosition control in the autofocus. This control can 
> be set by the user in the AfModeManual but it should also be reported 
> for each frame in the metadata.
> 
> This value is not the VCM value, but a normalized distance based on the 
> hyperfocale. To be able, from the AF algorithm, to fill the value (or to 
> set it) the hyperfocale value needs to be known for the lens used.

So far, so good.

> Right now, we have a CameraLens class, which controls the VCM driver. 
> But a lens is not only the VCM, but a couple sensor/VCM mounted in a 
> module. I found this page to be interesting to have a high level 
> understanding btw [1].

It is (and if you pay attention to the image sensor format and sensor
width in the calculator widget at the top you will curse whoever
invented the concept of sensor optical format), but it's about the focal
length only, not the focal distance.

> The issue, right now, is that we don't have anything else than the 
> sensor driver model, or the vcm model, nothing else, so we can't 
> automatically find the lens tuning parameters in a file or a cpp structure.
> 
> [1]: https://www.arducam.com/focal-length-calculator/
> 
> This is why, with a RFC tag, I tried something based on the VCM model. 
> But after some discussions, it looks like it is not solving it at all, 
> and a better way will be to have a tuning file, set by the userspace.
> 
> Now, it makes me wonder: how can we send a LensPosition in a 
> non-calibrated lens case ?

If you mean uncalibrated in the Android sense, it's simple: you pick a
random hyperfocal distance, and you're done. You will still need to
determine the valid lens motion range, and map that to the
[0.0, minimum focus distance] interval, but the minimum focus distance
value is freely picked.

> Thanks !
> JM
> PS: this series will obviously be dropped ;-).
> 
> >> This series is a RFC as it is not really clear, for instance, which
> >> properties may be useful (a macroRange and a FullRange sound like
> >> something useful for instance ?) and which units should be used for
> >> hyperfocale.
> >>
> >> I don't have a tuned sensor (and indeed, I really wish I could have a
> >> way to tune it properly :-)) so the values here must be used as examples
> >> only.
> >>
> >> Patch 3/4 is a specific property, in order to address one of the
> >> AfControls series "todo".
> >>
> >> Currently, we may use a range as large as the one reported by the
> >> V4L2_CID_FOCUS_ABSOLUTE call, but all may not be valid.
> >> For instance, some drivers can set 10 bits values, but only the first 9
> >> are relevant, as the macro mode is limited by the lens properties.
> >> We may want to have multiple ranges in a near future (macro, full,
> >> limited ?) and for the ease the range is returned as a libcamera::Size
> >> object, as I don't really know what would be better yet ;-).
> >>
> >> Patch 4/4 is the hyperfocale value, expressed in millimeters. Is it the
> >> correct unit is a question too :-).
> >>
> >> Thanks !
> >> JM
> >>
> >> Jean-Michel Hautbois (4):
> >>    libcamera: Add a camera lens properties database
> >>    libcamera: lens: Grab the static properties at init time
> >>    libcamera: lens: Add a helper to get the fixed range lens values
> >>    libcamera: lens: Add the hyperfocale property support
> >>
> >>   include/libcamera/internal/camera_lens.h      |  5 ++
> >>   .../internal/camera_lens_properties.h         | 25 +++++++
> >>   src/libcamera/camera_lens.cpp                 | 24 ++++++-
> >>   src/libcamera/camera_lens_properties.cpp      | 70 +++++++++++++++++++
> >>   src/libcamera/meson.build                     |  1 +
> >>   5 files changed, 124 insertions(+), 1 deletion(-)
> >>   create mode 100644 include/libcamera/internal/camera_lens_properties.h
> >>   create mode 100644 src/libcamera/camera_lens_properties.cpp