2016-09-27 00:06:28 +00:00
|
|
|
import QtQuick 2.5
|
2017-01-10 11:01:26 +00:00
|
|
|
import QtQuick.Window 2.0
|
|
|
|
import QtQuick.Controls 2.0
|
2016-09-27 00:06:28 +00:00
|
|
|
import QtQuick.Layouts 1.1
|
|
|
|
import QtMultimedia 5.5
|
|
|
|
|
|
|
|
import QZXing 2.3
|
|
|
|
|
|
|
|
ApplicationWindow
|
|
|
|
{
|
|
|
|
id: window
|
|
|
|
visible: true
|
|
|
|
width: 640
|
|
|
|
height: 480
|
|
|
|
title: "Qt QZXing Filter Test"
|
|
|
|
|
2017-01-10 11:01:26 +00:00
|
|
|
property int detectedTags: 0
|
|
|
|
property string lastTag: ""
|
|
|
|
|
2016-09-27 00:06:28 +00:00
|
|
|
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
|
2017-01-10 11:01:26 +00:00
|
|
|
text: "Tags detected: " + detectedTags
|
2016-09-27 00:06:28 +00:00
|
|
|
}
|
2016-12-19 10:32:20 +00:00
|
|
|
Text
|
|
|
|
{
|
|
|
|
id: fps
|
|
|
|
font.pixelSize: 20
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.right: parent.right
|
|
|
|
z: 50
|
|
|
|
text: (1000 / zxingFilter.timePerFrameDecode).toFixed(0) + "fps"
|
|
|
|
}
|
2016-09-27 00:06:28 +00:00
|
|
|
|
|
|
|
Camera
|
|
|
|
{
|
|
|
|
id:camera
|
2017-01-10 11:01:26 +00:00
|
|
|
focus {
|
|
|
|
focusMode: CameraFocus.FocusContinuous
|
|
|
|
focusPointMode: CameraFocus.FocusPointAuto
|
|
|
|
}
|
2016-09-27 00:06:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VideoOutput
|
|
|
|
{
|
|
|
|
id: videoOutput
|
|
|
|
source: camera
|
|
|
|
anchors.top: text1.bottom
|
|
|
|
anchors.bottom: text2.top
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
2017-01-10 11:01:26 +00:00
|
|
|
autoOrientation: true
|
2017-01-10 11:44:04 +00:00
|
|
|
fillMode: VideoOutput.Stretch
|
2016-09-27 00:06:28 +00:00
|
|
|
filters: [ zxingFilter ]
|
2017-01-10 11:01:26 +00:00
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: {
|
|
|
|
camera.focus.customFocusPoint = Qt.point(mouse.x / width, mouse.y / height);
|
|
|
|
camera.focus.focusMode = CameraFocus.FocusMacro;
|
|
|
|
camera.focus.focusPointMode = CameraFocus.FocusPointCustom;
|
|
|
|
}
|
|
|
|
}
|
2017-01-10 11:44:04 +00:00
|
|
|
Rectangle {
|
|
|
|
id: captureZone
|
|
|
|
color: "red"
|
|
|
|
opacity: 0.2
|
|
|
|
width: parent.width / 2
|
|
|
|
height: parent.height / 2
|
|
|
|
anchors.centerIn: parent
|
|
|
|
}
|
2016-09-27 00:06:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QZXingFilter
|
|
|
|
{
|
|
|
|
id: zxingFilter
|
2017-01-10 11:44:04 +00:00
|
|
|
captureRect: {
|
|
|
|
// setup bindings
|
|
|
|
videoOutput.contentRect;
|
|
|
|
videoOutput.sourceRect;
|
|
|
|
return videoOutput.mapRectToSource(videoOutput.mapNormalizedRectToItem(Qt.rect(
|
|
|
|
0.25, 0.25, 0.5, 0.5
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
2017-01-10 11:01:26 +00:00
|
|
|
decoder {
|
|
|
|
enabledDecoders: QZXing.DecoderFormat_EAN_13 | QZXing.DecoderFormat_CODE_39 | QZXing.DecoderFormat_QR_CODE
|
2016-09-27 00:06:28 +00:00
|
|
|
|
2017-01-10 11:01:26 +00:00
|
|
|
onTagFound: {
|
|
|
|
console.log(tag + " | " + decoder.foundedFormat() + " | " + decoder.charSet());
|
|
|
|
|
|
|
|
window.detectedTags++;
|
|
|
|
window.lastTag = tag;
|
|
|
|
}
|
2016-09-27 00:06:28 +00:00
|
|
|
|
2017-01-10 11:50:14 +00:00
|
|
|
tryHarder: false
|
2016-09-27 00:06:28 +00:00
|
|
|
}
|
|
|
|
|
2017-01-10 11:01:26 +00:00
|
|
|
onDecodingStarted:
|
2016-09-27 00:06:28 +00:00
|
|
|
{
|
2017-01-10 11:01:26 +00:00
|
|
|
// console.log("started");
|
2016-09-27 00:06:28 +00:00
|
|
|
}
|
|
|
|
|
2016-12-19 10:32:20 +00:00
|
|
|
property int framesDecoded: 0
|
|
|
|
property real timePerFrameDecode: 0
|
|
|
|
|
2017-01-10 11:01:26 +00:00
|
|
|
onDecodingFinished:
|
2016-09-27 00:06:28 +00:00
|
|
|
{
|
2016-12-19 10:32:20 +00:00
|
|
|
timePerFrameDecode = (decodeTime + framesDecoded * timePerFrameDecode) / (framesDecoded + 1);
|
|
|
|
framesDecoded++;
|
2020-02-12 09:37:14 +00:00
|
|
|
if(succeeded)
|
|
|
|
console.log("frame finished: " + succeeded, decodeTime, timePerFrameDecode, framesDecoded);
|
2016-09-27 00:06:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Text
|
|
|
|
{
|
|
|
|
id: text2
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
font.pixelSize: 20
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.left: parent.left
|
|
|
|
z: 50
|
2017-01-10 11:01:26 +00:00
|
|
|
text: "Last tag: " + lastTag
|
|
|
|
}
|
|
|
|
Switch {
|
|
|
|
text: "Autofocus"
|
|
|
|
checked: camera.focus.focusMode === CameraFocus.FocusContinuous
|
|
|
|
anchors {
|
|
|
|
right: parent.right
|
|
|
|
bottom: parent.bottom
|
|
|
|
}
|
|
|
|
onCheckedChanged: {
|
|
|
|
if (checked) {
|
|
|
|
camera.focus.focusMode = CameraFocus.FocusContinuous
|
|
|
|
camera.focus.focusPointMode = CameraFocus.FocusPointAuto
|
|
|
|
} else {
|
|
|
|
camera.focus.focusPointMode = CameraFocus.FocusPointCustom
|
|
|
|
camera.focus.customFocusPoint = Qt.point(0.5, 0.5)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
font.family: Qt.platform.os === 'android' ? 'Droid Sans Mono' : 'Monospace'
|
|
|
|
font.pixelSize: Screen.pixelDensity * 5
|
2016-09-27 00:06:28 +00:00
|
|
|
}
|
|
|
|
}
|