Updated QZXingLive example: use of QZXingFilter to comply with Qt 6.2 #199

This commit is contained in:
Nikolaos Ftylitakis 2021-11-03 11:28:28 +02:00
parent efbc26f3ea
commit ea066e1cb2
3 changed files with 168 additions and 0 deletions

View File

@ -23,7 +23,11 @@ Application::Application()
void Application::initializeQML()
{
#if QT_VERSION < 0x060200
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
#else
engine.load(QUrl(QStringLiteral("qrc:/main_qt6_2.qml")));
#endif // QT_VERSION < 0x060200
}
void Application::checkPermissions()

View File

@ -0,0 +1,163 @@
import QtQuick 2.5
import QtQuick.Window 2.0
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.1
import QtMultimedia
import QZXing 3.2
ApplicationWindow
{
id: window
visible: true
width: 640
height: 480
title: "Qt QZXing Filter Test"
property int detectedTags: 0
property string lastTag: ""
Rectangle
{
id: bgRect
color: "white"
anchors.fill: videoOutput
}
Text
{
id: text1
wrapMode: Text.Wrap
font.pixelSize: 20
anchors.top: parent.top
anchors.left: parent.left
z: 50
text: "Tags detected: " + detectedTags
}
Text
{
id: fps
font.pixelSize: 20
anchors.top: parent.top
anchors.right: parent.right
z: 50
text: (1000 / zxingFilter.timePerFrameDecode).toFixed(0) + "fps"
}
Camera
{
id:camera
active: true
focusMode: Camera.FocusModeAutoNear
}
CaptureSession {
camera: camera
videoOutput: videoOutput
}
VideoOutput
{
id: videoOutput
anchors.top: text1.bottom
anchors.bottom: text2.top
anchors.left: parent.left
anchors.right: parent.right
fillMode: VideoOutput.Stretch
property double captureRectStartFactorX: 0.25
property double captureRectStartFactorY: 0.25
property double captureRectFactorWidth: 0.5
property double captureRectFactorHeight: 0.5
MouseArea {
anchors.fill: parent
onClicked: {
camera.customFocusPoint = Qt.point(mouseX / width, mouseY / height);
camera.focusMode = Camera.FocusModeManual;
}
}
Rectangle {
id: captureZone
color: "red"
opacity: 0.2
width: parent.width * parent.captureRectFactorWidth
height: parent.height * parent.captureRectFactorHeight
x: parent.width * parent.captureRectStartFactorX
y: parent.height * parent.captureRectStartFactorY
}
}
QZXingFilter
{
id: zxingFilter
videoSink: videoOutput.videoSink
captureRect: {
videoOutput.sourceRect;
return Qt.rect(videoOutput.sourceRect.width * videoOutput.captureRectStartFactorX,
videoOutput.sourceRect.height * videoOutput.captureRectStartFactorY,
videoOutput.sourceRect.width * videoOutput.captureRectFactorWidth,
videoOutput.sourceRect.height * videoOutput.captureRectFactorHeight)
}
decoder {
enabledDecoders: QZXing.DecoderFormat_EAN_13 | QZXing.DecoderFormat_CODE_39 | QZXing.DecoderFormat_QR_CODE
onTagFound: {
console.log(tag + " | " + decoder.foundedFormat() + " | " + decoder.charSet());
window.detectedTags++;
window.lastTag = tag;
}
tryHarder: false
}
onDecodingStarted:
{
// console.log("started");
}
property int framesDecoded: 0
property real timePerFrameDecode: 0
onDecodingFinished:
{
timePerFrameDecode = (decodeTime + framesDecoded * timePerFrameDecode) / (framesDecoded + 1);
framesDecoded++;
if(succeeded)
console.log("frame finished: " + succeeded, decodeTime, timePerFrameDecode, framesDecoded);
}
}
Text
{
id: text2
wrapMode: Text.Wrap
font.pixelSize: 20
anchors.bottom: parent.bottom
anchors.left: parent.left
z: 50
text: "Last tag: " + lastTag
}
Switch {
text: "Autofocus"
checked: camera.focusMode === Camera.FocusModeAutoNear
anchors {
right: parent.right
bottom: parent.bottom
}
onCheckedChanged: {
if (checked) {
camera.focusMode = Camera.FocusModeAutoNear
} else {
camera.focusMode = Camera.FocusModeManual
camera.customFocusPoint = Qt.point(0.5, 0.5)
}
}
font.family: Qt.platform.os === 'android' ? 'Droid Sans Mono' : 'Monospace'
font.pixelSize: Screen.pixelDensity * 5
}
}

View File

@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>main_qt6_2.qml</file>
</qresource>
</RCC>