Proof of concept decoding of an QR code works (but is not displayed yet).
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 19 Jul 2017 20:03:42 +0000 (22:03 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 19 Jul 2017 20:03:42 +0000 (22:03 +0200)
qtapp/barcode2cash/mainwindow.cpp

index a75f458ba4d7e725d41cd68eff6960efafa4e443..ac9a2a2f2ba0ba4c00df2e4857afd3c7d139bbf3 100644 (file)
@@ -69,6 +69,39 @@ void MainWindow::showCaptureError(int, QCameraImageCapture::Error error, QString
 
 
 void MainWindow::analyze() {
-    QPixmap image("test.jpg");
-    ui->labAnalyzeImage->setPixmap(image);
+    QImage qimage("test.jpg");
+    qimage = qimage.convertToFormat(QImage::Format_Grayscale8);
+    auto zbimage = zbar::Image(qimage.width(), qimage.height(), "GREY", qimage.constBits(), qimage.byteCount());
+    auto scanner = zbar::ImageScanner();
+    auto scan_results = scanner.scan(zbimage);
+    if (scan_results > 0) {
+        auto results = scanner.get_results();
+        for (auto resit = results.symbol_begin(); resit != results.symbol_end(); ++ resit) {
+            if (resit->get_type() == zbar::ZBAR_QRCODE) {
+                QString qrcode_data = QString::fromStdString(resit->get_data());
+                // https://github.com/a-sit-plus/at-registrierkassen-mustercode/releases/download/1.2-DOK/2016-09-05-Detailfragen-RKSV-V1.2.pdf
+                auto parts = qrcode_data.split("_");
+                if (parts.size() != 14) continue; // QR code found but not RKSV
+                parts.takeFirst();
+                auto rlat = parts.takeFirst();
+                auto device_id = parts.takeFirst();
+                auto receipt_id = parts.takeFirst();
+                auto date_time = parts.takeFirst();
+                auto cash0 = parts.takeFirst();
+                auto cash1 = parts.takeFirst();
+                auto cash2 = parts.takeFirst();
+                auto cash3 = parts.takeFirst();
+                auto cash4 = parts.takeFirst();
+                auto counter = parts.takeFirst();
+                auto cert_serial = parts.takeFirst();
+                auto sig_prev = parts.takeFirst();
+                auto sig = parts.takeFirst();
+
+                break;
+            }
+        }
+    }
+
+    if (qimage.width() > 500) qimage = qimage.scaledToWidth(500);
+    ui->labAnalyzeImage->setPixmap(QPixmap::fromImage(qimage));
 }