Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zxing-cpp/example/ZXingQt5CamReader.qml @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /* | |
| 2 * Copyright 2020 Axel Waggershauser | |
| 3 */ | |
| 4 // SPDX-License-Identifier: Apache-2.0 | |
| 5 | |
| 6 import QtQuick 2.12 | |
| 7 import QtQuick.Window 2.12 | |
| 8 import QtQuick.Controls 2.5 | |
| 9 import QtQuick.Layouts 1.12 | |
| 10 import QtQuick.Shapes 1.12 | |
| 11 import QtMultimedia 5.12 | |
| 12 import ZXing 1.0 | |
| 13 | |
| 14 Window { | |
| 15 visible: true | |
| 16 width: 640 | |
| 17 height: 480 | |
| 18 title: Qt.application.name | |
| 19 | |
| 20 property var nullPoints: [Qt.point(0,0), Qt.point(0,0), Qt.point(0,0), Qt.point(0,0)] | |
| 21 property var points: nullPoints | |
| 22 | |
| 23 Timer { | |
| 24 id: resetInfo | |
| 25 interval: 1000 | |
| 26 } | |
| 27 | |
| 28 BarcodeReader { | |
| 29 id: barcodeReader | |
| 30 | |
| 31 formats: (linearSwitch.checked ? (ZXing.LinearCodes) : ZXing.None) | (matrixSwitch.checked ? (ZXing.MatrixCodes) : ZXing.None) | |
| 32 tryRotate: tryRotateSwitch.checked | |
| 33 tryHarder: tryHarderSwitch.checked | |
| 34 tryInvert: tryInvertSwitch.checked | |
| 35 tryDownscale: tryDownscaleSwitch.checked | |
| 36 textMode: ZXing.HRI | |
| 37 | |
| 38 // callback with parameter 'barcode', called for every successfully processed frame | |
| 39 onFoundBarcode: (barcode)=> { | |
| 40 points = [barcode.position.topLeft, barcode.position.topRight, barcode.position.bottomRight, barcode.position.bottomLeft] | |
| 41 info.text = qsTr("Format: \t %1 \nText: \t %2 \nType: \t %3 \nTime: \t %4 ms").arg(barcode.formatName).arg(barcode.text).arg(barcode.contentTypeName).arg(runTime) | |
| 42 | |
| 43 resetInfo.restart() | |
| 44 // console.log(barcode) | |
| 45 } | |
| 46 | |
| 47 // called for every processed frame where no barcode was detected | |
| 48 onFailedRead: ()=> { | |
| 49 points = nullPoints | |
| 50 | |
| 51 if (!resetInfo.running) | |
| 52 info.text = "No barcode found (in %1 ms)".arg(runTime) | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 Camera { | |
| 57 id: camera | |
| 58 | |
| 59 captureMode: Camera.CaptureViewfinder | |
| 60 deviceId: QtMultimedia.availableCameras[camerasComboBox.currentIndex] ? QtMultimedia.availableCameras[camerasComboBox.currentIndex].deviceId : "" | |
| 61 | |
| 62 onDeviceIdChanged: { | |
| 63 focus.focusMode = CameraFocus.FocusContinuous | |
| 64 focus.focusPointMode = CameraFocus.FocusPointAuto | |
| 65 } | |
| 66 | |
| 67 onError: console.log("camera error:" + errorString) | |
| 68 } | |
| 69 | |
| 70 ColumnLayout { | |
| 71 anchors.fill: parent | |
| 72 | |
| 73 RowLayout { | |
| 74 Layout.fillWidth: true | |
| 75 Layout.fillHeight: false | |
| 76 visible: QtMultimedia.availableCameras.length > 1 | |
| 77 Label { | |
| 78 text: qsTr("Camera: ") | |
| 79 Layout.fillWidth: false | |
| 80 } | |
| 81 ComboBox { | |
| 82 id: camerasComboBox | |
| 83 Layout.fillWidth: true | |
| 84 model: QtMultimedia.availableCameras | |
| 85 textRole: "displayName" | |
| 86 currentIndex: 0 | |
| 87 } | |
| 88 } | |
| 89 | |
| 90 VideoOutput { | |
| 91 id: videoOutput | |
| 92 Layout.fillHeight: true | |
| 93 Layout.fillWidth: true | |
| 94 filters: [barcodeReader] | |
| 95 source: camera | |
| 96 autoOrientation: true | |
| 97 | |
| 98 Shape { | |
| 99 id: polygon | |
| 100 anchors.fill: parent | |
| 101 visible: points.length == 4 | |
| 102 ShapePath { | |
| 103 strokeWidth: 3 | |
| 104 strokeColor: "red" | |
| 105 strokeStyle: ShapePath.SolidLine | |
| 106 fillColor: "transparent" | |
| 107 //TODO: really? I don't know qml... | |
| 108 startX: videoOutput.mapPointToItem(points[3]).x | |
| 109 startY: videoOutput.mapPointToItem(points[3]).y | |
| 110 PathLine { | |
| 111 x: videoOutput.mapPointToItem(points[0]).x | |
| 112 y: videoOutput.mapPointToItem(points[0]).y | |
| 113 } | |
| 114 PathLine { | |
| 115 x: videoOutput.mapPointToItem(points[1]).x | |
| 116 y: videoOutput.mapPointToItem(points[1]).y | |
| 117 } | |
| 118 PathLine { | |
| 119 x: videoOutput.mapPointToItem(points[2]).x | |
| 120 y: videoOutput.mapPointToItem(points[2]).y | |
| 121 } | |
| 122 PathLine { | |
| 123 x: videoOutput.mapPointToItem(points[3]).x | |
| 124 y: videoOutput.mapPointToItem(points[3]).y | |
| 125 } | |
| 126 } | |
| 127 } | |
| 128 | |
| 129 Label { | |
| 130 id: info | |
| 131 color: "white" | |
| 132 padding: 10 | |
| 133 background: Rectangle { color: "#80808080" } | |
| 134 } | |
| 135 | |
| 136 ColumnLayout { | |
| 137 anchors.right: parent.right | |
| 138 anchors.bottom: parent.bottom | |
| 139 | |
| 140 Switch {id: tryRotateSwitch; text: qsTr("Try Rotate"); checked: true } | |
| 141 Switch {id: tryHarderSwitch; text: qsTr("Try Harder"); checked: true } | |
| 142 Switch {id: tryInvertSwitch; text: qsTr("Try Invert"); checked: true } | |
| 143 Switch {id: tryDownscaleSwitch; text: qsTr("Try Downscale"); checked: true } | |
| 144 Switch {id: linearSwitch; text: qsTr("Linear Codes"); checked: true } | |
| 145 Switch {id: matrixSwitch; text: qsTr("Matrix Codes"); checked: true } | |
| 146 } | |
| 147 } | |
| 148 } | |
| 149 } |
