-
Notifications
You must be signed in to change notification settings - Fork 346
/
Copy pathmain_qt6_2.qml
166 lines (144 loc) · 4.39 KB
/
main_qt6_2.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
158
159
160
161
162
163
164
165
166
import QtQuick 2.5
import QtQuick.Window 2.0
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.1
import QtMultimedia
import QZXing 3.3
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
}
Component.onCompleted: { camera.active = false; camera.active = true; }
}
QZXingFilter
{
id: zxingFilter
videoSink: videoOutput.videoSink
orientation: videoOutput.orientation
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
}
}