All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jacopo Mondi <jacopo@jmondi.org>
To: Tomasz Figa <tfiga@google.com>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	"open list:MEDIA INPUT INFRASTRUCTURE (V4L/DVB)" 
	<linux-media@vger.kernel.org>
Subject: Re: [PATCH v2 03/10] media: v4l2-ctrl: Document V4L2_CID_CAMERA_SENSOR_ROTATION
Date: Tue, 3 Sep 2019 17:22:35 +0200	[thread overview]
Message-ID: <20190903152235.iw72hxka7kpf25s6@uno.localdomain> (raw)
In-Reply-To: <CAAFQd5CTn_6gDZL+kxN=112JW1tRSXo2PG1-twgnYycb0uGPYA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 8712 bytes --]

Hi Tomasz, Laurent

On Tue, Sep 03, 2019 at 01:16:21PM +0900, Tomasz Figa wrote:
> On Tue, Sep 3, 2019 at 1:43 AM Laurent Pinchart
> <laurent.pinchart@ideasonboard.com> wrote:
> >
> > Hi Jacopo,
> >
> > On Mon, Sep 02, 2019 at 01:20:49PM +0200, Jacopo Mondi wrote:
> > > On Tue, Aug 27, 2019 at 03:51:32PM +0300, Laurent Pinchart wrote:
> > > > On Tue, Aug 27, 2019 at 11:23:29AM +0200, Jacopo Mondi wrote:
> > > >> Add documentation for the V4L2_CID_CAMERA_SENSOR_ROTATION camera
> > > >> control. The newly added read-only control reports the camera device
> > > >> mounting rotation.
> > > >>
> > > >> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> > > >> ---
> > > >>  Documentation/media/uapi/v4l/ext-ctrls-camera.rst | 9 +++++++++
> > > >>  1 file changed, 9 insertions(+)
> > > >>
> > > >> diff --git a/Documentation/media/uapi/v4l/ext-ctrls-camera.rst b/Documentation/media/uapi/v4l/ext-ctrls-camera.rst
> > > >> index ecf151f3f0f4..03d1c23d18f7 100644
> > > >> --- a/Documentation/media/uapi/v4l/ext-ctrls-camera.rst
> > > >> +++ b/Documentation/media/uapi/v4l/ext-ctrls-camera.rst
> > > >> @@ -544,6 +544,15 @@ enum v4l2_scene_mode -
> > > >>
> > > >>
> > > >>
> > > >> +``V4L2_CID_CAMERA_SENSOR_ROTATION (integer)``
> > > >> +    This read-only control describes the camera sensor orientation by
> > > >> +    reporting its mounting rotation in respect to the device intended usage
> > > >> +    orientation, expressed in counter clockwise degrees. The control value is
> > > >
> > > > Counter clockwise relative to what ? :-)
> > >
> > > I think it is expressed in the previous line:
> > > "mounting rotation in respect to the device intended usage
> > > orientation, expressed in counter clockwise degrees"
> > >
> > > Would you prefer to have this re-phrased as:
> > >
> > > This read-only control describes the camera sensor orientation
> > > expressed as rotation in counter clockwise degrees in respect to
> > > the device intended usage orientation.
> > >
> > > ?
> >
> > Rotation is expressed in degrees around an axis, which is itself
> > expressed as a vector. It's pretty intuitive that the rotation vector
> > should be perpendicular to the plane of the sensor (which itself should
> > be parallel to the plane of the device side on which it is mounted, as
> > expressed by the location property), but there are still two possible
> > directions for the vector, facing in the same direction as the sensor or
> > the opposite direction. Unless there's a good reason to do so, I would
> > use the same direction as the one defined by Android. I don't know what
> > direction that is though :-)

What about:
   This read-only control describes the sensor orientation
   expressed as rotation in counterclockwise degrees along the axis
   perpendicular to the device mounting reference plane, assuming a
   canonical right-handed orientation with the y axis being positive
   towards the system's top and negative towards the bottom, and the
   axis directed pointing away from the sensor lens. Possible values
   for the control are 90, 180 and 270 degrees. To compensate the
   device mounting rotation on the captured images, a rotation of
   the same amount of degrees, in the same counterclockwise rotation
   direction should be applied along the axis directed from the
   observer to the captured image when displayed on a screen

This is for the control, while the 'rotation' DT property is simply
documented as:

- rotation: The device, typically an image sensor, is not mounted upright,
  but a number of degrees counter clockwise. Typical values are 0 and 180
  (upside down).

I would expand it with a description of the effects of rotation on
captured images and how that should be compensated.

Let me have some ascii-art fun:
-------------------------------------------------------------------------------

  To understand the effect of the sensor rotation on the acquired
  images, it is helpful to consider a fictional scan-out sequence of
  the sensor's pixels.

  Assuming the pixel array having its top-left pixel at position (0,
  0) with x increasing towards the right direction, and y increasing
  towards the bottom direction, the effect of sensor rotation could be
  easily visualized considering the sequence of captured pixels.

  Assuming the following scene has to be captured

                o
               -|-
               / \

  An upright mounted sensor has its pixel array displaced as follows

                                 x
      (0,0)---------------------->
        ! 0,0 0,1 0,2 ... 0,line-len
        ! 1,0 1,1 1,2 ...
        ! ...
        ! ...
        ! (num-col,0)...  (num-col,line-len)
      y V


  Assuming pixels are scanned out from (0,0) to (num-col,line-len)
  progressively.

    (0,0) ------------------> (0,line-len)---!
      !------------------------------------<-!
      V
    (1,0) ------------------> (1,line-len)---!
      !------------------------------------<-!
      V
    (...) .-----------------> ( ,,,, )    ---!
      !------------------------------------<-!
      V
    (num-col,0)------------->(num-col,line-len)

  If a rotation of 90 degrees counterclockwise along the axis
  perpendicular to the sensor's lens and directed towards the scene
  to be captured is applied to the sensor, the pixel array would then
  be rotated as follows

      x ^  0,line-len,,,(num-col,line-len
        !  ....
        !  0,2 1,2      ...
        !  0,1 1,1      ...
        !  0,0 1,0 ... num-col,0
       (0,0)------------------------>
                                   y

   And the pixel scan-out sequence would then proceed as follows

   (0,line-len)            (num-cols,line-len)
        ^\    ^\    ^\    ^\    ^
        ! \   ! \   ! \   ! \   !
        !  \  !  \  !  \  !  \  !
        !   \ !   \ !   \ !   \ !
        !    \!    \!    \!    \!
      (0,0)  (1,0) ....      (num-cols,0)

   Which when applied on the capture scene gives

   (0,line-len)            (num-cols,line-len)
        ^\    ^\    ^\    ^\    ^
        ! \   ! \   0 \   ! \   !
        !  \  !  \ -|- \  !  \  !
        !   \ !    / \  \ !   \ !
        !    \!    \!    \!    \!
      (0,0)  (1,0) ....      (num-cols,0)

   Producing the following image once captured to memory and
   displayed to the user

         \ !
           --0
         / !

   which (ascii-art shortcomings apart in the drawing) has a rotation
   of the  same amount of degrees applied on the opposite rotation direction
   along the axis that goes from the observer to the displayed image.

   To summarize, to compensate the sensor mounting rotation, when expressed
   as counterclockwise rotation along the axis directed from the sensor
   the captured scene, a rotation of the same amount of degrees in the
   same counterclockwise rotation direction applied along the axis
   directed from the observer to the captured image, has to be applied.

 -------                     -------                        -------
 |   o  |  90deg sensor      | \ !  |  90degrees image      |   o  |
 |  -|- |  counterclockwise  |  --0 | counterclockwise      |  -|- |
 |  / \ |  mounting rotation | / !  | compensation rotation |  / \ |
 -------                     -------                        -------

------------------End of ascii-art fun -----------------------------------------

As it took me some off-line discussions to get this right (thanks :)
do you think something along these lines should be anywhere in the
control or the property documentation ?

I know you're still in favour of going from something like the
'mount-matrix' property Rob suggested, but I still think it's an
unnecessary complication for such a 'trivial' concept. Asking developers
to provide a 3D rotation matrix where they could only express
rotations of 90 degrees multiples on 2 axes out of tree is calling for
them simply ignoring this complication and going for custom methods to
report the mounting rotation.

>
> I don't think Android exposes camera rotation to the layers above the
> HAL. The stream is expected to be pre-rotated by the HAL, taking into
> account the desired target rotation of the stream itself [1].
>
> [1] https://android.googlesource.com/platform/hardware/libhardware/+/master/include/hardware/camera3.h#1428
>
> That said, Android seems to use "degrees counterclockwise" for rotations.

https://jmondi.org/android_metadata_tags/docs.html#static_android.lens.facing
I see the property description reporting

"Clockwise angle through which the output image needs to be rotated to be
upright on the device screen in its native orientation."

Who knows which direction of the rotation axis do they take into
account :)

Thanks
  j

>
> Best regards,
> Tomasz

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2019-09-03 15:21 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-27  9:23 [PATCH v2 00/10] media: Report camera sensor properties Jacopo Mondi
2019-08-27  9:23 ` [PATCH v2 01/10] media: dt-bindings: Document 'location' property Jacopo Mondi
2019-08-27  9:23   ` Jacopo Mondi
2019-08-27 12:21   ` Laurent Pinchart
2019-08-27 12:21     ` Laurent Pinchart
2019-08-29 12:46     ` Jacopo Mondi
2019-08-29 12:46       ` Jacopo Mondi
2019-09-02 13:38       ` Rob Herring
2019-09-02 13:38         ` Rob Herring
2019-09-02 16:40         ` Jacopo Mondi
2019-09-02 16:40           ` Jacopo Mondi
2019-09-02 16:49           ` Laurent Pinchart
2019-09-02 16:49             ` Laurent Pinchart
2019-09-02 19:48             ` Jacopo Mondi
2019-09-02 19:48               ` Jacopo Mondi
2019-09-03 13:22               ` Laurent Pinchart
2019-09-03 13:22                 ` Laurent Pinchart
2019-09-12 12:51     ` Mauro Carvalho Chehab
2019-09-12 16:36       ` Jacopo Mondi
2019-08-27  9:23 ` [PATCH v2 02/10] media: v4l2-ctrl: Document V4L2_CID_CAMERA_SENSOR_LOCATION Jacopo Mondi
2019-08-27 12:50   ` Laurent Pinchart
2019-08-29 12:47     ` Jacopo Mondi
2019-08-27  9:23 ` [PATCH v2 03/10] media: v4l2-ctrl: Document V4L2_CID_CAMERA_SENSOR_ROTATION Jacopo Mondi
2019-08-27 12:51   ` Laurent Pinchart
2019-09-02 11:20     ` Jacopo Mondi
2019-09-02 16:43       ` Laurent Pinchart
2019-09-03  4:16         ` Tomasz Figa
2019-09-03 13:17           ` Laurent Pinchart
2019-09-03 15:22           ` Jacopo Mondi [this message]
2019-08-27  9:23 ` [PATCH v2 04/10] media: v4l2-ctrl: Add V4L2_CID_CAMERA_SENSOR_LOCATION Jacopo Mondi
2019-08-27 12:53   ` Laurent Pinchart
2019-08-27  9:23 ` [PATCH v2 04/10] media: v4l2-ctrls: " Jacopo Mondi
2019-08-27  9:36   ` Jacopo Mondi
2019-08-27  9:23 ` [PATCH v2 05/10] media: v4l2-ctrl: Add V4L2_CID_CAMERA_SENSOR_ROTATION Jacopo Mondi
2019-08-27 13:07   ` Laurent Pinchart
2019-08-27  9:23 ` [PATCH v2 05/10] media: v4l2-ctrls: " Jacopo Mondi
2019-08-27  9:36   ` Jacopo Mondi
2019-08-27  9:23 ` [PATCH v2 06/10] media: v4l2-fwnode: Add helper to register controls from fw Jacopo Mondi
2019-08-27 13:16   ` Laurent Pinchart
2019-08-29 12:55     ` Jacopo Mondi
2019-08-29 10:31   ` Hans Verkuil
2019-08-29 12:45     ` Jacopo Mondi
2019-08-29 13:04       ` Hans Verkuil
2019-08-29 15:05         ` Laurent Pinchart
2019-08-29 15:32           ` Hans Verkuil
2019-09-02  9:39             ` Jacopo Mondi
2019-09-02  9:46             ` Laurent Pinchart
2019-08-27  9:23 ` [PATCH v2 07/10] media: i2c: ov5670: Register controls from firmware Jacopo Mondi
2019-08-27  9:23 ` [PATCH v2 08/10] media: i2c: ov13858: " Jacopo Mondi
2019-08-27  9:23 ` [PATCH v2 09/10] media: i2c: ov5670: Report native size and crop bounds Jacopo Mondi
2019-08-29 10:20   ` Hans Verkuil
2019-08-29 12:40     ` Jacopo Mondi
2019-08-29 12:55       ` Hans Verkuil
2019-08-29 13:18         ` Jacopo Mondi
2019-08-29 13:39           ` Hans Verkuil
2019-08-29 16:43             ` Jacopo Mondi
2019-09-02 10:05               ` Laurent Pinchart
2019-09-03 13:06         ` Sakari Ailus
2019-09-03 16:49           ` Jacopo Mondi
2019-09-26  8:11             ` Hans Verkuil
2019-09-26 18:56               ` Jacopo Mondi
2019-10-07 14:23                 ` Tomasz Figa
2019-08-27  9:23 ` [PATCH v2 10/10] media: i2c: ov13858: " Jacopo Mondi
2019-08-27  9:23 ` [DO NOT MERGE] mb/google/poppy/variant/soraka: Add camera properties Jacopo Mondi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190903152235.iw72hxka7kpf25s6@uno.localdomain \
    --to=jacopo@jmondi.org \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=tfiga@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.