Skip to content

Commit 035404b

Browse files
committed
added barcode false positive detection
1 parent 082333f commit 035404b

File tree

3 files changed

+62
-5
lines changed

3 files changed

+62
-5
lines changed

CHANGELOG.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [0.10.3]
5+
6+
### Added
7+
- Barcode false positive detection
8+
49
## [0.10.2]
510

6-
## Fixed
11+
### Fixed
712
- Fixed checkout cancelling
813
- Product search item cells should now scale with multiline text
914

1015
## [0.10.1]
1116

12-
## Added
17+
### Added
1318
- Experimental support for IKEA vendor specific codes
1419

15-
## Changed
20+
### Changed
1621
- ITF code detection is now restricted to ITF14
1722

1823
## [0.10.0]

ui/src/main/java/io/snabble/sdk/ui/scanner/BarcodeScannerView.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public class BarcodeScannerView extends FrameLayout implements TextureView.Surfa
9898
private int bitsPerPixel;
9999
private boolean indicatorEnabled = true;
100100
private FrameLayout splashView;
101+
private FalsePositiveFilter falsePositiveFilter = new FalsePositiveFilter();
101102

102103
public BarcodeScannerView(Context context) {
103104
super(context);
@@ -227,6 +228,7 @@ public void resume() {
227228
cameraHandler.post(new Runnable() {
228229
@Override
229230
public void run() {
231+
resetFalsePositiveFilter();
230232
isPaused = false;
231233

232234
if (!running) {
@@ -264,6 +266,7 @@ private void startIfRequested() {
264266
return;
265267
}
266268

269+
resetFalsePositiveFilter();
267270
setupZXing();
268271

269272
showError(false);
@@ -393,6 +396,15 @@ public void run() {
393396
}
394397
}
395398

399+
private void resetFalsePositiveFilter() {
400+
barcodeProcessingHandler.post(new Runnable() {
401+
@Override
402+
public void run() {
403+
falsePositiveFilter.reset();
404+
}
405+
});
406+
}
407+
396408
private void chooseOptimalPreviewSize(Camera.Parameters parameters) {
397409
Camera.Size optimalSize = getOptimalPreviewSize();
398410

@@ -675,8 +687,11 @@ public void run() {
675687
finalResult.getText(),
676688
finalResult.getTimestamp());
677689

678-
Logger.d("Detected barcode: " + barcode.toString());
679-
callback.onBarcodeDetected(barcode);
690+
Barcode filtered = falsePositiveFilter.filter(barcode);
691+
if (filtered != null) {
692+
Logger.d("Detected barcode: " + barcode.toString());
693+
callback.onBarcodeDetected(barcode);
694+
}
680695
}
681696
}
682697
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package io.snabble.sdk.ui.scanner;
2+
3+
import io.snabble.sdk.utils.Logger;
4+
5+
public class FalsePositiveFilter {
6+
private final static int REPEATS_NEEDED = 2;
7+
8+
private Barcode lastBarcode;
9+
private int repeats = 0;
10+
11+
public FalsePositiveFilter() {
12+
13+
}
14+
15+
public synchronized void reset() {
16+
repeats = 0;
17+
lastBarcode = null;
18+
}
19+
20+
public synchronized Barcode filter(Barcode barcode) {
21+
if (lastBarcode == null
22+
|| (lastBarcode.getText().equals(barcode.getText())
23+
&& lastBarcode.getFormat().equals(barcode.getFormat()))) {
24+
repeats++;
25+
lastBarcode = barcode;
26+
} else {
27+
Logger.d("Filtered false positive: %s OR %s", lastBarcode, barcode);
28+
reset();
29+
}
30+
31+
if (repeats >= REPEATS_NEEDED) {
32+
return barcode;
33+
}
34+
35+
return null;
36+
}
37+
}

0 commit comments

Comments
 (0)