Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QML Camera focus doesn't work

How to focus with QML Camera on Android? I've tried all focusMode but nothing works. Camera apps correctly focus on my device.

Here my QML file:

import QtQuick 2.3
import QtMultimedia 5.2

Item {
    property int scanerButtonWidth: 80
    property int scanerButtonHeight: 60

    Rectangle {
        width: parent.width
        height: scanerButtonHeight + 10
        color: Qt.rgba(0,0,0,1)
    }

    VideoOutput {
        width: parent.width
        height: parent.height
        source: camera
        anchors.fill: parent
        autoOrientation: true
    }

    Camera {
        id: camera
        imageProcessing.whiteBalanceMode: CameraImageProcessing.WhiteBalanceFlash
        captureMode: Camera.CaptureStillImage
        exposure {
            exposureMode: Camera.ExposureAuto
        }

        focus {
            focusMode: Camera.FocusContinuous
            focusPointMode: Camera.FocusPointCenter
        }

        imageCapture {
            onImageCaptured: {
                otpGeneratorApp.scanedQR_Code( preview, false, type )
                qrCodeScanner.visible = false
            }
        }
    }


    Rectangle {
        width: parent.width
        height: scanerButtonHeight + 10
        y: parent.height - ( height )
        color: Qt.rgba(0,0,0,1)

        Button {
            id: captureButton;
            width: scanerButtonWidth;
            height: scanerButtonHeight;
            x: parent.width * 0.5 - ( width / 2);
            y: parent.height - ( height + 5);
            text: qsTr( "[O]" );
            onClicked: {
                 camera.imageCapture.capture();
            }
        }

        Button {
            id: focus
            width: scanerButtonWidth;
            height: scanerButtonHeight;
            text: qsTr("Focus");
            x: captureButton.x + ( captureButton.width + 10 );
            y: parent.height - ( height + 5);
            onClicked: {
                 camera.searchAndLock();
            }
        }
    }
}
like image 428
Andreas Avatar asked Nov 09 '22 23:11

Andreas


1 Answers

If you are using Qt 5.4 or below, you cannot. There is a bug in QCamera that prevents the autofocus to be triggered. See the bug and a way to solve it here.

A solution has been merged and the bug is solved since Qt 5.5.

like image 149
Fabien Avatar answered Nov 14 '22 23:11

Fabien