From 98c1f05ed688680e5113c73117754d12e4493cb5 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 8 Nov 2021 10:30:56 +0200 Subject: [PATCH] double pass qr with wide and cropped image --- .../sparrow/control/WebcamService.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/control/WebcamService.java b/src/main/java/com/sparrowwallet/sparrow/control/WebcamService.java index c9fbd951..c0a190a5 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/WebcamService.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/WebcamService.java @@ -102,7 +102,7 @@ public class WebcamService extends ScheduledService { updateValue(image); if(System.currentTimeMillis() > (lastQrSampleTime + QR_SAMPLE_PERIOD_MILLIS)) { - readQR(croppedImage); + readQR(bimg, croppedImage); lastQrSampleTime = System.currentTimeMillis(); } @@ -129,15 +129,26 @@ public class WebcamService extends ScheduledService { return super.cancel(); } - private void readQR(BufferedImage bufferedImage) { + private void readQR(BufferedImage wideImage, BufferedImage croppedImage) { + Result result = readQR(wideImage); + if(result == null) { + result = readQR(croppedImage); + } + + if(result != null) { + resultProperty.set(result); + } + } + + private Result readQR(BufferedImage bufferedImage) { LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); try { - Result result = qrReader.decode(bitmap, Map.of(DecodeHintType.TRY_HARDER, Boolean.TRUE)); - resultProperty.set(result); + return qrReader.decode(bitmap, Map.of(DecodeHintType.TRY_HARDER, Boolean.TRUE)); } catch(ReaderException e) { // fall thru, it means there is no QR code in image + return null; } }