Closed
Description
QML
import QtQuick 2.12
import QtQuick.Window 2.12
import QtMultimedia 5.12
import QZXing 3.1
Item {
property string lastTag: ""
property int detectedTags: 0
property int nWidth: Math.min(width,height)
Rectangle{
id: bgRect
color: "white"
anchors.fill: videoOutput
}
Text{
id: text1
wrapMode: Text.Wrap
color:"red"
z: 50
text: "Detected count: " + 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.fill: parent
autoOrientation: true
filters: [ zxingFilter ]
MouseArea {
anchors.fill: parent
onClicked: {
console.log("VideoOutput.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
width: nWidth*0.6
height: width
anchors.centerIn: parent
color:"transparent"
border.color: "lightgreen"
border.width: 3
Rectangle{
id:line
width: parent.width*0.9
height: 12
color: "lightgreen"
anchors.horizontalCenter: parent.horizontalCenter
radius: 8
PropertyAnimation{
id:ani
target:line
properties: "y"
duration: 1500
from:0
running: true
to:captureZone.height - line.height
onStopped: {
y=0
ani.start()
}
}
}
}
}
QZXingFilter{
id: zxingFilter
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("onTagFound: ",tag + " | " + decoder.foundedFormat() + " | " + decoder.charSet());
detectedTags++;
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{
wrapMode: Text.Wrap
color:"red"
anchors.bottom: parent.bottom
z: 50
text: "content: " + lastTag
}
}
main.cpp
....
QApplication app(argc, argv);
QZXing::registerQMLTypes();
....
return app.exec()
....
Metadata
Assignees
Labels
No labels