[libcamera-devel] [PATCH 04/23] libcamera: properties: Add rotation property

Niklas Söderlund niklas.soderlund at ragnatech.se
Wed Jan 15 00:16:43 CET 2020


Hi Jacopo,

Thanks for a great effort in writing this up!

On 2020-01-13 17:42:26 +0100, Jacopo Mondi wrote:
> The rotation property describes the rotation of the camera sensor.
> 
> Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>

This matches my view of our discussions, nice work!

My only concern is that a shark is swimming in front of the laptop 
webcam example ;-)

Reviewed-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>

> ---
>  src/libcamera/property_ids.yaml | 309 ++++++++++++++++++++++++++++++++
>  1 file changed, 309 insertions(+)
> 
> diff --git a/src/libcamera/property_ids.yaml b/src/libcamera/property_ids.yaml
> index aaadcbd3e52b..243af7bd0a03 100644
> --- a/src/libcamera/property_ids.yaml
> +++ b/src/libcamera/property_ids.yaml
> @@ -25,4 +25,313 @@ controls:
>            description: |
>              The camera is attached to the device in a way that allows it to
>              be moved freely
> +
> +  - Rotation:
> +      type: int32_t
> +      description: |
> +        The camera rotation is expressed as the angular difference in degrees
> +        between two reference systems, one implicitly defined by the camera
> +        module intrinsics characteristics, and one artificially defined on the
> +        external world scene to be captured when projected on the image sensor
> +        pixel array.
> +
> +        A camera sensor has an implicitly defined 2-dimensional reference
> +        system 'Rc' defined by its pixel array scan-out order, with its origin
> +        posed at pixel address (0,0), the x-axis progressing from there towards
> +        the last scanned out column of the pixel array and the y-axis
> +        progressing towards the last scanned out line.
> +
> +        A typical example for a sensor with a (2592x1944) pixel array matrix
> +        observed from the front is
> +
> +                   (2592)      x-axis          0
> +                      <------------------------+ 0
> +                      .......... ... ..........!
> +                      .......... ... ..........! y-axis
> +                                 ...           !
> +                      .......... ... ..........!
> +                      .......... ... ..........! (1944)
> +                                               V
> +
> +        The external world scene reference system scene 'Rs' is defined as a
> +        2-dimensional reference system on the parallel plane posed in front
> +        of the camera module's focal plane, with its origin placed on the
> +        visible top-left corner, the x-axis progressing towards the right from
> +        there and the y-axis progressing towards the bottom of the visible
> +        scene.
> +
> +        A typical example of a (very common) picture of a shark swimming from
> +        left to right is
> +
> +                                 x-axis
> +                   (0,0)---------------------->
> +                     !
> +                     !
> +                     !       |\____)\___
> +                     !       ) _____  __`<
> +                     !       |/     )/
> +                     !
> +                     V
> +                   y-axis
> +
> +        With the reference plane posed in front of the camera module and
> +        parallel to its focal plane
> +
> +                                   !
> +                                 / !
> +                                /  !
> +                               /   !
> +                        _     /    !
> +                     +-/ \-+ /     !
> +                     | (o) |       ! 'Rs' reference plane
> +                     +-----+ \     !
> +                              \    !
> +                               \   !
> +                                \  !
> +                                 \ !
> +                                   !
> +
> +        When projected on the sensor's pixel array, the image and the associated
> +        reference system 'Rs' are typically inverted, due to the camera module's
> +        lens optical inversion effect.
> +
> +        Assuming the above represented scene of the swimming shark, the lens
> +        inversion projects on the sensor pixel array the reference plane 'Rp'
> +
> +                  y-axis
> +                     ^
> +                     !
> +                     !       |\_____)\__
> +                     !       ) ____  ___.<
> +                     !       |/    )/
> +                     !
> +                     !
> +                   (0,0)---------------------->
> +                                 x-axis
> +
> +        The camera rotation property is then defined as the angular difference
> +        in counterclockwise direction between the origin of the camera reference
> +        system 'Rc', defined by the camera sensor scan-out direction and its
> +        mounting position, and the origin of the projected scene reference
> +        system 'Rp', result of the optical projection of the scene reference
> +        system 'Rs' on the sensor pixel array.
> +
> +        Examples
> +
> +        0 degrees camera rotation
> +
> +                          y-Rp
> +                    y-Rc   ^
> +                     ^     !
> +                     !     !
> +                     !     !
> +                     !     !
> +                     !     !
> +                     !     !
> +                     !   (0,0)---------------------->
> +                     !                 x-Rp
> +                   0 +------------------------------------->
> +                      0            x-Rc
> +
> +
> +                                     x-Rc          0
> +                           <------------------------+ 0
> +                                x-Rp                !
> +                     <-----------------------(0,0)  !
> +                                               !    !
> +                                               !    !
> +                                               !    !
> +                                               !    V
> +                                               !  y-Rc
> +                                               V
> +                                             y-Rp
> +
> +        90 degrees camera rotation
> +
> +                      0        y-Rc
> +                   0 +----------------------->
> +                     !
> +                     !    y-Rp
> +                     !     ^
> +                     !     !
> +                     !     !
> +                     !     !
> +                     !     !
> +                     !     !
> +                     !     !
> +                     !   (0,0)---------------------->
> +                     !                 x-Rp
> +                     !
> +                     V
> +                   x-Rc
> +
> +        180 degrees camera rotation
> +
> +                                   x-Cr          0
> +                         <------------------------+ 0
> +                     y-Rp                         !
> +                      ^                           !
> +                      !                           ! y-Cr
> +                      !                           !
> +                      !                           !
> +                      !                           V
> +                      !
> +                      !
> +                    (0,0)--------------------->
> +                                   x-Rp
> +
> +        270 degrees camera rotation
> +
> +                      0        y-Rc
> +                   0 +----------------------->
> +                     !            x-Rp
> +                     ! <-----------------------(0,0
> +                     !                           !
> +                     !                           !
> +                     !                           !
> +                     !                           !
> +                     !                           !
> +                     !                           V
> +                     !                         y-Rp
> +                     !
> +                     !
> +                     V
> +                   x-Rc
> +
> +
> +
> +        Example one - Webcam
> +
> +        A camera module installed on the user facing part of a laptop screen
> +        casing used for video calls. The captured images are meant to be
> +        displayed in landscape mode (width > height) on the laptop screen.
> +
> +        The camera is typically mounted 180 degrees rotated to compensate the
> +        lens optical inversion effect.
> +
> +                          y-Rp
> +                    y-Rc   ^
> +                     ^     !
> +                     !     !       |\_____)\__
> +                     !     !       ) ____  ___.<
> +                     !     !       |/    )/
> +                     !     !
> +                     !     !
> +                     !   (0,0)---------------------->
> +                     !                 x-Rp
> +                   0 +------------------------------------->
> +                      0                x-Rc
> +
> +        The two reference systems are aligned, the resulting camera rotation is
> +        0 degrees, no rotation correction should be applied to the resulting
> +        image once captured to memory buffers to correctly display it to users.
> +
> +                     +--------------------------+
> +                     !       |\____)\___        !
> +                     !       ) _____  __`<      !
> +                     !       |/     )/          !
> +                     +--------------------------+
> +
> +        If the camera module is not mounted 180 degrees rotated to compensate
> +        the lens optical inversion, the two reference system will result not
> +        aligned, with 'Rp' plane 180 degrees rotated in respect to the 'Rc'
> +        plane.
> +
> +                                   x-Rc          0
> +                         <------------------------+ 0
> +                     y-Rp                         !
> +                      ^                           !
> +                      !                           ! y-Rc
> +                      !      |\_____)\__          !
> +                      !      ) ____  ___.<        !
> +                      !      |/    )/             V
> +                      !
> +                      !
> +                    (0,0)--------------------->
> +                                   x-Rp
> +
> +        The image once captured to memory will then be 180 degrees rotated
> +
> +                     +--------------------------+
> +                     !          __/(_____/|     !
> +                     !        >.___  ____ (     !
> +                     !             \(    \|     !
> +                     +--------------------------+
> +
> +        A software rotation correction of 180 degrees should be applied to
> +        correctly display the image.
> +
> +                     +--------------------------+
> +                     !       |\____)\___        !
> +                     !       ) _____  __`<      !
> +                     !       |/     )/          !
> +                     +--------------------------+
> +
> +        Example two - Phone camera
> +
> +        A camera installed on the back-side of a mobile device facing away from
> +        the user. The captured images are meant to be displayed in portrait mode
> +        (height > width) to match the device screen orientation and the device
> +        usage orientation used when taking the picture.
> +
> +        The camera is typically mounted with its pixel array longer side aligned
> +        to the device longer side, 180 degrees rotated to compensate the lens
> +        optical inversion effect.
> +
> +                      0        y-Rc
> +                   0 +----------------------->
> +                     !
> +                     !    y-Rp
> +                     !     ^
> +                     !     !
> +                     !     !       |\_____)\__
> +                     !     !       ) ____  ___.<
> +                     !     !       |/    )/
> +                     !     !
> +                     !     !
> +                     !   (0,0)---------------------->
> +                     !                 x-Rp
> +                     !
> +                     !
> +                     V
> +                   x-Rc
> +
> +        The two reference systems are not aligned and the 'Rp' reference
> +        system is 90 degrees rotated in counterclockwise direction in respect
> +        to the 'Rc' reference system.
> +
> +        The image, when captured to memory buffer will be rotated.
> +
> +                     +---------------------------------------+
> +                     |                  _ _                  |
> +                     |                 \   /                 |
> +                     |                  | |                  |
> +                     |                  | |                  |
> +                     |                  |  >                 |
> +                     |                 <  |                  |
> +                     |                  | |                  |
> +                     |                    .                  |
> +                     |                   V                   |
> +                     +---------------------------------------+
> +
> +        A correction of 90 degrees in counterclockwise direction has to be
> +        applied to correctly display the image in portrait mode on the device
> +        screen.
> +
> +                                +-----------------+
> +                                |                 |
> +                                |                 |
> +                                |                 |
> +                                |                 |
> +                                |                 |
> +                                |                 |
> +                                |  |\____)\___    |
> +                                |  ) _____  __`<  |
> +                                |  |/     )/      |
> +                                |                 |
> +                                |                 |
> +                                |                 |
> +                                |                 |
> +                                |                 |
> +                                +-----------------+
>  ...
> -- 
> 2.24.0
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel at lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

-- 
Regards,
Niklas Söderlund


More information about the libcamera-devel mailing list