mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
double pass qr with wide and cropped image
This commit is contained in:
parent
90439501ad
commit
98c1f05ed6
1 changed files with 15 additions and 4 deletions
|
@ -102,7 +102,7 @@ public class WebcamService extends ScheduledService<Image> {
|
||||||
updateValue(image);
|
updateValue(image);
|
||||||
|
|
||||||
if(System.currentTimeMillis() > (lastQrSampleTime + QR_SAMPLE_PERIOD_MILLIS)) {
|
if(System.currentTimeMillis() > (lastQrSampleTime + QR_SAMPLE_PERIOD_MILLIS)) {
|
||||||
readQR(croppedImage);
|
readQR(bimg, croppedImage);
|
||||||
lastQrSampleTime = System.currentTimeMillis();
|
lastQrSampleTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,15 +129,26 @@ public class WebcamService extends ScheduledService<Image> {
|
||||||
return super.cancel();
|
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);
|
LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
|
||||||
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
|
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Result result = qrReader.decode(bitmap, Map.of(DecodeHintType.TRY_HARDER, Boolean.TRUE));
|
return qrReader.decode(bitmap, Map.of(DecodeHintType.TRY_HARDER, Boolean.TRUE));
|
||||||
resultProperty.set(result);
|
|
||||||
} catch(ReaderException e) {
|
} catch(ReaderException e) {
|
||||||
// fall thru, it means there is no QR code in image
|
// fall thru, it means there is no QR code in image
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue