[Interest] QML Camera: resulting image is rotated

ekke ekke at ekkes-corner.org
Sun Dec 9 18:17:39 CET 2018


Am 09.12.18 um 16:57 schrieb Alexander Ivash:
> Is it possible to understand the angle to un-rotate? I've tried to
> un-rotate based on orientation from VideoOtput but it doesn't work
> uniformly on all the devices.
>
> Regards, Alexander
> Open Tracking
>
> _______________________________________________
> Interest mailing list
> Interest at lists.qt-project.org
> https://lists.qt-project.org/listinfo/interest

Alexander,

from my experiences it's not so easy.

it depends from device and how the camera module is physically mounted

so I'm doing it for my customers hardcoded while waiting that QML will
handle this

here's some code from customer app

it's on my TODO to extract the code and create example app and blog and
create all the specific issues - but expect 2019

To get some ideas:

// V I D E O   O U T P U T
VideoOutput {
    source: camera
    anchors.fill: parent
    focus : visible
    autoOrientation: true
    rotation: isIos && isFrontFace ? 180:0
} // Video Output


// P R E V I E W   I M A G E
Image {
    id: photoPreview
    fillMode: Image.PreserveAspectFit
     anchors.fill: parent
     property bool isPortraitAtCaptureTime: false
    // i O S   BUG
    // on iOS we don't use autoTransform - otherwise orientation would
be wrong
    // instead we're calculating rotation of Image
    // we also must calculate rotation 180 for VideoOutput if iOS and
FrontFace
   // see also
   // https://bugreports.qt.io/browse/QTBUG-50056
   // test also front camera bugs
https://bugreports.qt.io/browse/QTBUG-37955 and
https://bugreports.qt.io/browse/QTBUG-67985
   autoTransform: isIos? false : true
   rotation: 0
 } // photoPreview

// ROTATE BEFORE CAPTURE
// iOS rotation calculated in cpp:
int PhotoUtil::cameraScreenRotation(const bool isBackFace, const int
cameraOrientation)
{
    const int screenAngle =
mScreen->angleBetween(mScreen->nativeOrientation(), mScreen->orientation());
    int rotation;
    if (isBackFace) {
        rotation = (360 - cameraOrientation + screenAngle) % 360;
    } else {
        rotation = (cameraOrientation - screenAngle) % 360;
    }
    return rotation;
}
if(isIos) {
   
photoUtil.rotateScaleSaveCapturedImage(camera.imageCapture.capturedImagePath,
requestId, theEntity, photoPreview.rotation)
} else {
    // X C O V E R
    if(isSamsungXCover) {
        if(photoPreview.isPortraitAtCaptureTime) {
            if(isBackFace) {
                // PORTRAIT BACK: rotate 90°
               
photoUtil.rotateScaleSaveCapturedImage(camera.imageCapture.capturedImagePath,
requestId, theEntity, 90)
            } else {
                // PORTRAIT FRONT: rotate -90°
               
photoUtil.rotateScaleSaveCapturedImage(camera.imageCapture.capturedImagePath,
requestId, theEntity, -90)
            }
        } else {
            // LANDSCAPE BACK or FRONT: rotate 180°
           
photoUtil.rotateScaleSaveCapturedImage(camera.imageCapture.capturedImagePath,
requestId, theEntity, 180)
        }
    }
    // P I X E L    C
    else if(isPixelC) {
        if(photoPreview.isPortraitAtCaptureTime) {
            if(isBackFace) {
                // PORTRAIT BACK: rotate 90°
               
photoUtil.rotateScaleSaveCapturedImage(camera.imageCapture.capturedImagePath,
requestId, theEntity, 90)
            } else {
                // PORTRAIT FRONT: rotate -90°
               
photoUtil.rotateScaleSaveCapturedImage(camera.imageCapture.capturedImagePath,
requestId, theEntity, -90)
            }
        } else {
            // LANDSCAPE BACK or FRONT: OK
           
photoUtil.rotateScaleSaveCapturedImage(camera.imageCapture.capturedImagePath,
requestId, theEntity, 0)
        }
    }
    // NO SPECIAL DEVICE WITH MANAGED ORIENTATION
    else {
       
photoUtil.rotateScaleSaveCapturedImage(camera.imageCapture.capturedImagePath,
requestId, theEntity, 0)
    }
}

have tried with some devices and also created a Settings Page where
customer can enter rotation needed for FrontFace or BackFace camera for
a specific model, so I can add this

ekke

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20181209/0dca4c71/attachment.html>


More information about the Interest mailing list