Discussion:
[Interest] QML Camera: resulting image is rotated
Alexander Ivash
2018-12-09 15:57:28 UTC
Permalink
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
René Hansen
2018-12-10 08:51:44 UTC
Permalink
Forgot to add, that m_filter->camera() in the snippet above, is just a
reference to a Camera QML component.
QCamera *cam = qvariant_cast<QCamera
*>(m_filter->camera()->property("mediaObject"));
QCameraInfo(*cam).orientation()
Then in case orientation is not % 180, you can rotate the image.
/René
Thanks!
But frankly speaking this is not the answer I hoped to get :).
;-)
Have you tried to extract rotation from exif / metadata? This is what I'm
going to do if don't find better way.
have not tried this. please let me know if you'll find a way
In my case VideoOutput always shows preview in correct orientation,
have you tested on iOS and FrontFace Camera ? in my use-cases I needed
rotation of 180 for preview (VideoOutput)
so looks like Qt *knows* how to rotate preview frames properly (why
doesn't it use this knowledge to rotate saved image or why doesn't it
expose it - this is another question). But if Qt knows - there should be
some source of information where it gets such a knowledge.
haven't found any info about
ciao
ekke
Regards, Alexander
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
[image: Open Tracking]
_______________________________________________
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
// 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
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
_______________________________________________
Interest mailing list
https://lists.qt-project.org/listinfo/interest
[image: Open Tracking]
_______________________________________________
Interest mailing list
https://lists.qt-project.org/listinfo/interest
ekke
2018-12-10 09:08:01 UTC
Permalink
I'm already using a reference to Camera QML component to get some
properties (WhiteBalance, Exposure, ...)
but have not used yet QCamera to get the Orientation from
thanks for the tip - will try later if this is working on all devices,
FronFace, BackFace, Portrait, Landscape
ekke
Forgot to add, that m_filter->camera() in the snippet above, is just a
reference to a Camera QML component.
QCamera *cam = qvariant_cast<QCamera
*>(m_filter->camera()->property("mediaObject"));
QCameraInfo(*cam).orientation()
Then in case orientation is not % 180, you can rotate the image.
/René
Thanks!
But frankly speaking this is not the answer I hoped to get :).
;-)
Have you tried to extract rotation from exif / metadata? This
is what I'm going to do if don't find better way.
have not tried this. please let me know if you'll find a way
In my case VideoOutput always shows preview in correct orientation,
have you tested on iOS and FrontFace Camera ? in my use-cases
I needed rotation of 180 for preview (VideoOutput)
so looks like Qt /knows/ how to rotate preview frames
properly (why doesn't it use this knowledge to rotate saved
image or why doesn't it expose it - this is another
question). But if Qt knows - there should be some source of
information where it gets such a knowledge.
haven't found any info about
ciao
ekke
Regards, Alexander
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
|
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
// 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
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
_______________________________________________
Interest mailing list
https://lists.qt-project.org/listinfo/interest
Open Tracking
_______________________________________________
Interest mailing list
https://lists.qt-project.org/listinfo/interest
Alexander Ivash
2018-12-10 09:53:17 UTC
Permalink
QCamera *cam = qvariant_cast<QCamera
*>(m_filter->camera()->property("mediaObject"));
QCameraInfo(*cam).orientation()
Then in case orientation is not % 180, you can rotate the image.
Is it the same as QML Camera's 'orientation' ?
http://doc.qt.io/qt-5/qml-qtmultimedia-camera.html#orientation-prop
Or this is actual orientation? Maybe you could share sample which
'unrotate' based on this property?
Artem Sidyakin
2018-12-11 03:47:54 UTC
Permalink
As far as I know, it is impossible to tell in which position the camera is before you actually see its viewfinder in VideoOutput :)

In my case I had a camera upside-down, so 180 degree rotation. I managed it like this:

property bool cameraUpsideDown: true

Camera {
id: camera
metaData.orientation: cameraUpsideDown ? 180 : 0
// ...
}

VideoOutput {
orientation: cameraUpsideDown ? 180 : 0
source: camera
// ...
}

And then if you need to preview images made by this camera you can bind their orientation to EXIF values:

Image {
autoTransform: true
// ...
}

But I feel like I misunderstood your question.

---
Artem Sidyakin
QCamera *cam = qvariant_cast<QCamera *>(m_filter->camera()->property("mediaObject"));
QCameraInfo(*cam).orientation()
Then in case orientation is not % 180, you can rotate the image.
Is it the same as QML Camera's 'orientation' ? http://doc.qt.io/qt-5/qml-qtmultimedia-camera.html#orientation-prop
Or this is actual orientation? Maybe you could share sample which 'unrotate' based on this property?
_______________________________________________
Interest mailing list
https://lists.qt-project.org/listinfo/interest
Loading...