From d3b0eac51a163476f91862c2c3e15975009bff39 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Thu, 29 Feb 2024 15:32:29 +0200 Subject: [PATCH] improve qr reading by additionally scanning using boofcv --- build.gradle | 1 + .../sparrowwallet/sparrow/control/WebcamService.java | 12 ++++++++++++ src/main/java/module-info.java | 1 + 3 files changed, 14 insertions(+) diff --git a/build.gradle b/build.gradle index 30f36db6..bc04bd62 100644 --- a/build.gradle +++ b/build.gradle @@ -124,6 +124,7 @@ dependencies { exclude group: 'org.slf4j' } implementation('com.sparrowwallet.nightjar:nightjar:0.2.40') + implementation('com.sparrowwallet.bokmakierie:bokmakierie:1.0') implementation('io.reactivex.rxjava2:rxjava:2.2.15') implementation('io.reactivex.rxjava2:rxjavafx:2.2.2') implementation('org.apache.commons:commons-lang3:3.7') diff --git a/src/main/java/com/sparrowwallet/sparrow/control/WebcamService.java b/src/main/java/com/sparrowwallet/sparrow/control/WebcamService.java index 74d7f263..510852f4 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/WebcamService.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/WebcamService.java @@ -5,6 +5,7 @@ import com.google.zxing.*; import com.google.zxing.client.j2se.BufferedImageLuminanceSource; import com.google.zxing.common.HybridBinarizer; import com.google.zxing.qrcode.QRCodeReader; +import com.sparrowwallet.bokmakierie.Bokmakierie; import com.sparrowwallet.sparrow.io.Config; import javafx.beans.property.BooleanProperty; import javafx.beans.property.ObjectProperty; @@ -43,6 +44,7 @@ public class WebcamService extends ScheduledService { private Webcam cam; private long lastQrSampleTime; private final Reader qrReader; + private final Bokmakierie bokmakierie; static { Webcam.setDriver(new WebcamScanDriver()); @@ -55,6 +57,7 @@ public class WebcamService extends ScheduledService { this.delayCalculator = delayCalculator; this.lastQrSampleTime = System.currentTimeMillis(); this.qrReader = new QRCodeReader(); + this.bokmakierie = new Bokmakierie(); } @Override @@ -156,6 +159,15 @@ public class WebcamService extends ScheduledService { LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); + try { + com.sparrowwallet.bokmakierie.Result result = bokmakierie.scan(bufferedImage); + if(result != null) { + return new Result(result.getMessage(), result.getRawBytes(), new ResultPoint[0], BarcodeFormat.QR_CODE); + } + } catch(Exception e) { + log.debug("Error scanning QR", e); + } + if(ZBar.isEnabled()) { ZBar.Scan scan = ZBar.scan(bufferedImage); if(scan != null) { diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index eb7168b0..5b667b9c 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -62,6 +62,7 @@ open module com.sparrowwallet.sparrow { requires net.coobird.thumbnailator; requires com.github.hervegirod; requires com.sparrowwallet.toucan; + requires com.sparrowwallet.bokmakierie; requires java.smartcardio; requires com.jcraft.jzlib; } \ No newline at end of file