QRCodeReader (WIP)
This commit is contained in:
parent
d38e40d53f
commit
6744dce57e
5 changed files with 251 additions and 90 deletions
|
@ -3,6 +3,7 @@ import QtQuick.Controls 2.12
|
|||
import PageEnum 1.0
|
||||
import QtMultimedia 5.5
|
||||
import QZXing 3.2
|
||||
import QRCodeReader 1.0
|
||||
|
||||
import "./"
|
||||
import "../Controls"
|
||||
|
@ -51,108 +52,126 @@ PageBase {
|
|||
|
||||
Item {
|
||||
anchors.fill: parent
|
||||
Camera
|
||||
{
|
||||
id:camera
|
||||
focus {
|
||||
focusMode: CameraFocus.FocusContinuous
|
||||
focusPointMode: CameraFocus.FocusPointAuto
|
||||
|
||||
QRCodeReader {
|
||||
id: qrCodeReader
|
||||
|
||||
onCodeReaded: {
|
||||
QrDecoderLogic.onDetectedQrCode(code)
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
qrCodeReader.setCameraSize(Qt.rect(loader.x,
|
||||
loader.y,
|
||||
loader.width,
|
||||
loader.height))
|
||||
qrCodeReader.startReading()
|
||||
}
|
||||
Component.onDestruction: qrCodeReader.stopReading()
|
||||
}
|
||||
|
||||
VideoOutput
|
||||
{
|
||||
id: videoOutput
|
||||
source: camera
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
autoOrientation: true
|
||||
fillMode: VideoOutput.PreserveAspectFit
|
||||
filters: [ zxingFilter ]
|
||||
// Camera
|
||||
// {
|
||||
// id:camera
|
||||
// focus {
|
||||
// focusMode: CameraFocus.FocusContinuous
|
||||
// focusPointMode: CameraFocus.FocusPointAuto
|
||||
// }
|
||||
// }
|
||||
|
||||
// VideoOutput
|
||||
// {
|
||||
// id: videoOutput
|
||||
// source: camera
|
||||
// anchors.top: parent.top
|
||||
// anchors.bottom: parent.bottom
|
||||
// anchors.left: parent.left
|
||||
// anchors.right: parent.right
|
||||
// autoOrientation: true
|
||||
// fillMode: VideoOutput.PreserveAspectFit
|
||||
// filters: [ zxingFilter ]
|
||||
|
||||
|
||||
Rectangle {
|
||||
color: "black"
|
||||
opacity: 0.5
|
||||
width: videoOutput.contentRect.width *0.15
|
||||
height: videoOutput.contentRect.height
|
||||
x: (videoOutput.width - videoOutput.contentRect.width)/2
|
||||
anchors.verticalCenter: videoOutput.verticalCenter
|
||||
}
|
||||
// Rectangle {
|
||||
// color: "black"
|
||||
// opacity: 0.5
|
||||
// width: videoOutput.contentRect.width * 0.15
|
||||
// height: videoOutput.contentRect.height
|
||||
// x: (videoOutput.width - videoOutput.contentRect.width)/2
|
||||
// anchors.verticalCenter: videoOutput.verticalCenter
|
||||
// }
|
||||
|
||||
Rectangle {
|
||||
color: "black"
|
||||
opacity: 0.5
|
||||
width: videoOutput.contentRect.width *0.15
|
||||
height: videoOutput.contentRect.height
|
||||
x: videoOutput.width/2 + videoOutput.contentRect.width/2 - videoOutput.contentRect.width *0.15
|
||||
anchors.verticalCenter: videoOutput.verticalCenter
|
||||
}
|
||||
// Rectangle {
|
||||
// color: "black"
|
||||
// opacity: 0.5
|
||||
// width: videoOutput.contentRect.width * 0.15
|
||||
// height: videoOutput.contentRect.height
|
||||
// x: videoOutput.width/2 + videoOutput.contentRect.width/2 - videoOutput.contentRect.width * 0.15
|
||||
// anchors.verticalCenter: videoOutput.verticalCenter
|
||||
// }
|
||||
|
||||
Rectangle {
|
||||
color: "black"
|
||||
opacity: 0.5
|
||||
width: videoOutput.contentRect.width *0.7
|
||||
height: videoOutput.contentRect.height *0.15
|
||||
x: (videoOutput.width - videoOutput.contentRect.width)/2 + videoOutput.contentRect.width *0.15
|
||||
y: (videoOutput.height - videoOutput.contentRect.height)/2
|
||||
}
|
||||
// Rectangle {
|
||||
// color: "black"
|
||||
// opacity: 0.5
|
||||
// width: videoOutput.contentRect.width * 0.7
|
||||
// height: videoOutput.contentRect.height * 0.15
|
||||
// x: (videoOutput.width - videoOutput.contentRect.width)/2 + videoOutput.contentRect.width * 0.15
|
||||
// y: (videoOutput.height - videoOutput.contentRect.height)/2
|
||||
// }
|
||||
|
||||
Rectangle {
|
||||
color: "black"
|
||||
opacity: 0.5
|
||||
width: videoOutput.contentRect.width *0.7
|
||||
height: videoOutput.contentRect.height *0.15
|
||||
x: (videoOutput.width - videoOutput.contentRect.width)/2 + videoOutput.contentRect.width *0.15
|
||||
y: videoOutput.height/2 + videoOutput.contentRect.height/2 - videoOutput.contentRect.height *0.15
|
||||
}
|
||||
// Rectangle {
|
||||
// color: "black"
|
||||
// opacity: 0.5
|
||||
// width: videoOutput.contentRect.width * 0.7
|
||||
// height: videoOutput.contentRect.height * 0.15
|
||||
// x: (videoOutput.width - videoOutput.contentRect.width)/2 + videoOutput.contentRect.width * 0.15
|
||||
// y: videoOutput.height/2 + videoOutput.contentRect.height/2 - videoOutput.contentRect.height * 0.15
|
||||
// }
|
||||
|
||||
LabelType {
|
||||
width: parent.width
|
||||
text: qsTr("Decoded QR chunks " + QrDecoderLogic.receivedChunksCount + "/" + QrDecoderLogic.totalChunksCount)
|
||||
horizontalAlignment: Text.AlignLeft
|
||||
visible: QrDecoderLogic.totalChunksCount > 0
|
||||
anchors.horizontalCenter: videoOutput.horizontalCenter
|
||||
y: videoOutput.height/2 + videoOutput.contentRect.height/2
|
||||
}
|
||||
}
|
||||
// LabelType {
|
||||
// width: parent.width
|
||||
// text: qsTr("Decoded QR chunks " + QrDecoderLogic.receivedChunksCount + "/" + QrDecoderLogic.totalChunksCount)
|
||||
// horizontalAlignment: Text.AlignLeft
|
||||
// visible: QrDecoderLogic.totalChunksCount > 0
|
||||
// anchors.horizontalCenter: videoOutput.horizontalCenter
|
||||
// y: videoOutput.height/2 + videoOutput.contentRect.height/2
|
||||
// }
|
||||
// }
|
||||
|
||||
QZXingFilter
|
||||
{
|
||||
id: zxingFilter
|
||||
orientation: videoOutput.orientation
|
||||
captureRect: {
|
||||
// setup bindings
|
||||
videoOutput.contentRect;
|
||||
videoOutput.sourceRect;
|
||||
return videoOutput.mapRectToSource(videoOutput.mapNormalizedRectToItem(Qt.rect(
|
||||
0.15, 0.15, 0.7, 0.7 //0, 0, 1.0, 1.0
|
||||
)));
|
||||
}
|
||||
// QZXingFilter
|
||||
// {
|
||||
// id: zxingFilter
|
||||
// orientation: videoOutput.orientation
|
||||
// captureRect: {
|
||||
// // setup bindings
|
||||
// videoOutput.contentRect;
|
||||
// videoOutput.sourceRect;
|
||||
// return videoOutput.mapRectToSource(videoOutput.mapNormalizedRectToItem(Qt.rect(
|
||||
// 0.15, 0.15, 0.7, 0.7 //0, 0, 1.0, 1.0
|
||||
// )));
|
||||
// }
|
||||
|
||||
decoder {
|
||||
enabledDecoders: QZXing.DecoderFormat_QR_CODE
|
||||
// decoder {
|
||||
// enabledDecoders: QZXing.DecoderFormat_QR_CODE
|
||||
|
||||
onTagFound: {
|
||||
QrDecoderLogic.onDetectedQrCode(tag)
|
||||
}
|
||||
// onTagFound: {
|
||||
// QrDecoderLogic.onDetectedQrCode(tag)
|
||||
// }
|
||||
|
||||
tryHarder: true
|
||||
}
|
||||
// tryHarder: true
|
||||
// }
|
||||
|
||||
property int framesDecoded: 0
|
||||
property real timePerFrameDecode: 0
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
// onDecodingFinished:
|
||||
// {
|
||||
// timePerFrameDecode = (decodeTime + framesDecoded * timePerFrameDecode) / (framesDecoded + 1);
|
||||
// framesDecoded++;
|
||||
// if(succeeded)
|
||||
// console.log("frame finished: " + succeeded, decodeTime, timePerFrameDecode, framesDecoded);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue