Expand QZXingFilter example code

- allow autofocus and manual focus
- count number of tags matched
- allow configuring the barcode scanner from QML
This commit is contained in:
Milian Wolff 2017-01-10 12:01:26 +01:00
parent eba661a424
commit a7103d5cac
4 changed files with 57 additions and 35 deletions

View File

@ -7,16 +7,11 @@ QZXingFilter::QZXingFilter(QObject *parent)
: QAbstractVideoFilter(parent)
, decoding(false)
{
/// By default all the types are enabled but hence that it is extra processing.
decoder.setDecoder(QZXing::DecoderFormat_Aztec | QZXing::DecoderFormat_QR_CODE);
/// Conecting signals to handlers that will send signals to QML
connect(&decoder, &QZXing::decodingStarted,
this, &QZXingFilter::handleDecodingStarted);
connect(&decoder, &QZXing::decodingFinished,
this, &QZXingFilter::handleDecodingFinished);
connect(&decoder, &QZXing::tagFound,
this, &QZXingFilter::handleTagFound);
}
QZXingFilter::~QZXingFilter()
@ -38,12 +33,6 @@ void QZXingFilter::handleDecodingFinished(bool succeeded)
emit isDecodingChanged();
}
void QZXingFilter::handleTagFound(QString tag)
{
// qDebug() << "handleTagFound";
emit tagFound(tag);
}
QVideoFilterRunnable * QZXingFilter::createFilterRunnable()
{
return new QZXingFilterRunnable(this);

View File

@ -59,17 +59,16 @@ class QZXingFilter : public QAbstractVideoFilter
Q_OBJECT
Q_PROPERTY(bool decoding READ isDecoding NOTIFY isDecodingChanged)
Q_PROPERTY(QZXing* decoder READ getDecoder)
signals:
void isDecodingChanged();
void decodingFinished(bool succeeded, int decodeTime);
void tagFound(QString tag);
void decodingStarted();
private slots:
void handleDecodingStarted();
void handleDecodingFinished(bool succeeded);
void handleTagFound(QString tag);
private: /// Attributes
QZXing decoder;
@ -83,6 +82,7 @@ class QZXingFilter : public QAbstractVideoFilter
virtual ~QZXingFilter();
bool isDecoding() {return decoding; }
QZXing* getDecoder() { return &decoder; }
QVideoFilterRunnable * createFilterRunnable();

View File

@ -21,6 +21,7 @@ int main(int argc, char *argv[])
QQmlApplicationEngine engine;
qmlRegisterType<QZXingFilter>("QZXing", 2, 3, "QZXingFilter");
qmlRegisterType<QZXing>("QZXing", 2, 3, "QZXing");
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();

View File

@ -1,7 +1,7 @@
import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Window 2.0
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.1
import QtQuick.Dialogs 1.2
import QtMultimedia 5.5
import QZXing 2.3
@ -14,6 +14,9 @@ ApplicationWindow
height: 480
title: "Qt QZXing Filter Test"
property int detectedTags: 0
property string lastTag: ""
Rectangle
{
id: bgRect
@ -29,12 +32,16 @@ ApplicationWindow
anchors.top: parent.top
anchors.left: parent.left
z: 50
text: "......"
text: "Tags detected: " + detectedTags
}
Camera
{
id:camera
focus {
focusMode: CameraFocus.FocusContinuous
focusPointMode: CameraFocus.FocusPointAuto
}
}
VideoOutput
@ -45,37 +52,43 @@ ApplicationWindow
anchors.bottom: text2.top
anchors.left: parent.left
anchors.right: parent.right
// autoOrientation: true
autoOrientation: true
fillMode: VideoOutput.PreserveAspectCrop
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;
}
}
}
QZXingFilter
{
id: zxingFilter
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: true
}
onDecodingStarted:
{
// console.log("started");
}
onDecodingFinished:
{
if(succeeded)
{
}
else
{
}
}
onTagFound:
{
console.log("--!!--");
console.log(tag);
text1.text = "--00--";
text2.text = tag;
console.log("frame finished: " + succeeded, decodeTime);
}
}
@ -87,6 +100,25 @@ ApplicationWindow
anchors.bottom: parent.bottom
anchors.left: parent.left
z: 50
text: "Nothing yet..."
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
}
}