Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-85550

Invalid rotation being set for camera on android devices

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.14.2
    • Multimedia
    • None
    • Android

    Description

      Code for camera imageCapture on android sets rotation of camera based on orientation sensor, instead of using data on how android UI is orientated while creating a photo.


       

      The rotation which a camera uses on android is being calculated in

      src/qtmultimedia/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp

      in

      int QAndroidCameraSession::currentCameraRotation() const

      as

       

      // subtract natural camera orientation and physical device orientation
       int rotation = 0;
       int deviceOrientation = (AndroidMultimediaUtils::getDeviceOrientation() + 45) / 90 * 90;
       if (m_camera->getFacing() == AndroidCamera::CameraFacingFront)
       rotation = (m_nativeOrientation - deviceOrientation + 360) % 360;
       else // back-facing camera
       rotation = (m_nativeOrientation + deviceOrientation) % 360;
      

       

      and this value is passed to native cameraRotation ( https://developer.android.com/reference/android/hardware/Camera.Parameters#setRotation(int) ) whenever image is being capture in method

       

      int QAndroidCameraSession::capture(const QString &fileName)

      as

       

      // adjust picture rotation depending on the device orientation
       m_camera->setRotation(currentCameraRotation());

       

      So in many cases, when device is at 45 degrees, in position just UI to be re-orientated e.g. from portrait to landscape, camera will rotate result as if a device was already in landscape, while UI is still in portrait.

      This happens a lot e.g. if you take device with UI in portrait-orientation, and try to photo some text, placing a device horizontally to a table's surface, while slighly tilting it into landscape, but not fully enough for UI to go to landscape. In result you get imageCapture with wrong rotation.


       

      As of now the only way-out to determine correct orientation of result photo: redo all steps are being done inside QAndroidCameraSession::currentCameraRotation(), get rotation used by camera, compare it to rotation of UI when taking a photo, and if they differ: rotate captured image to needed angle.

      The correct behaviour of imageCapture would be to use UI's orientation's, instead of sensor's.

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            bartlomiejmoskal Bartlomiej Moskal
            savthegood Alex So
            Veli-Pekka Heinonen Veli-Pekka Heinonen
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes