-
Notifications
You must be signed in to change notification settings - Fork 346
/
Copy pathmain.qml
157 lines (141 loc) · 4.02 KB
/
main.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import QtQuick 2.5
import QtQuick.Window 2.0
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.1
import QtMultimedia 5.5
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
focus {
focusMode: CameraFocus.FocusContinuous
focusPointMode: CameraFocus.FocusPointAuto
}
}
VideoOutput
{
id: videoOutput
source: camera
anchors.top: text1.bottom
anchors.bottom: text2.top
anchors.left: parent.left
anchors.right: parent.right
autoOrientation: true
fillMode: VideoOutput.Stretch
filters: [ zxingFilter ]
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;
}
}
Rectangle {
id: captureZone
color: "red"
opacity: 0.2
width: parent.width / 2
height: parent.height / 2
anchors.centerIn: parent
}
}
QZXingFilter
{
id: zxingFilter
orientation: videoOutput.orientation
captureRect: {
// setup bindings
videoOutput.contentRect;
videoOutput.sourceRect;
return videoOutput.mapRectToSource(videoOutput.mapNormalizedRectToItem(Qt.rect(
0.25, 0.25, 0.5, 0.5
)));
}
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.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
}
}