From c2433d258276013b1df9e52df95a05520717bf70 Mon Sep 17 00:00:00 2001 From: pmneo Date: Thu, 13 Apr 2023 12:58:38 +0200 Subject: [PATCH] tryHarder for the WhiteRectangeDetector Proposal for a try harder variant of the WhiteRectableDetector to find a not centered Aztec and Data Matrix Code in a page --- .../detector/WhiteRectangleDetector.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/google/zxing/common/detector/WhiteRectangleDetector.java b/core/src/main/java/com/google/zxing/common/detector/WhiteRectangleDetector.java index 8d77b0de5..693119463 100644 --- a/core/src/main/java/com/google/zxing/common/detector/WhiteRectangleDetector.java +++ b/core/src/main/java/com/google/zxing/common/detector/WhiteRectangleDetector.java @@ -83,7 +83,31 @@ public final class WhiteRectangleDetector { * @throws NotFoundException if no Data Matrix Code can be found */ public ResultPoint[] detect() throws NotFoundException { - + if( this.tryHarder ) { + try { + return this.internalDetect(); + } + catch( NotFoundException e ) { + for( int x=0; x < image.getWidth(); x += 50 ) { + for( int y=0; y < image.getHeight(); y += 50 ) { + try { + return new WhiteRectangleDetector( image, INIT_SIZE, x, y ).internalDetect(); + } + catch( NotFoundException nfe ) { + //Ignore + } + } + } + //also try harder did not found anything + throw e; + } + } + else { + return this.internalDetect(); + } + } + + protected ResultPoint[] internalDetect() throws NotFoundException { int left = leftInit; int right = rightInit; int up = upInit;