mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Remove duplicate results when it has structured append header. (#1147)
* remove duplicate results in processStructuredAppend * add whitespace * remove illegal import
This commit is contained in:
parent
8a53ade692
commit
fedfa7a16c
|
@ -96,7 +96,7 @@ public final class QRCodeMultiReader extends QRCodeReader implements MultipleBar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Result> processStructuredAppend(List<Result> results) {
|
static List<Result> processStructuredAppend(List<Result> results) {
|
||||||
boolean hasSA = false;
|
boolean hasSA = false;
|
||||||
|
|
||||||
// first, check, if there is at least on SA result in the list
|
// first, check, if there is at least on SA result in the list
|
||||||
|
@ -114,9 +114,10 @@ public final class QRCodeMultiReader extends QRCodeReader implements MultipleBar
|
||||||
List<Result> newResults = new ArrayList<>();
|
List<Result> newResults = new ArrayList<>();
|
||||||
List<Result> saResults = new ArrayList<>();
|
List<Result> saResults = new ArrayList<>();
|
||||||
for (Result result : results) {
|
for (Result result : results) {
|
||||||
newResults.add(result);
|
|
||||||
if (result.getResultMetadata().containsKey(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE)) {
|
if (result.getResultMetadata().containsKey(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE)) {
|
||||||
saResults.add(result);
|
saResults.add(result);
|
||||||
|
} else {
|
||||||
|
newResults.add(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// sort and concatenate the SA list items
|
// sort and concatenate the SA list items
|
||||||
|
|
|
@ -19,8 +19,10 @@ package com.google.zxing.multi.qrcode;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.google.zxing.BarcodeFormat;
|
import com.google.zxing.BarcodeFormat;
|
||||||
|
@ -29,6 +31,7 @@ import com.google.zxing.BufferedImageLuminanceSource;
|
||||||
import com.google.zxing.LuminanceSource;
|
import com.google.zxing.LuminanceSource;
|
||||||
import com.google.zxing.Result;
|
import com.google.zxing.Result;
|
||||||
import com.google.zxing.ResultMetadataType;
|
import com.google.zxing.ResultMetadataType;
|
||||||
|
import com.google.zxing.ResultPoint;
|
||||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||||
import com.google.zxing.common.HybridBinarizer;
|
import com.google.zxing.common.HybridBinarizer;
|
||||||
import com.google.zxing.multi.MultipleBarcodeReader;
|
import com.google.zxing.multi.MultipleBarcodeReader;
|
||||||
|
@ -70,4 +73,38 @@ public final class MultiQRCodeTestCase extends Assert {
|
||||||
assertEquals(expectedContents, barcodeContents);
|
assertEquals(expectedContents, barcodeContents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testProcessStructuredAppend() {
|
||||||
|
Result sa1 = new Result("SA1", new byte[]{}, new ResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||||
|
Result sa2 = new Result("SA2", new byte[]{}, new ResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||||
|
Result sa3 = new Result("SA3", new byte[]{}, new ResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||||
|
sa1.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, (0 << 4) + 2);
|
||||||
|
sa1.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||||
|
sa2.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, (1 << 4) + 2);
|
||||||
|
sa2.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||||
|
sa3.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, (2 << 4) + 2);
|
||||||
|
sa3.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||||
|
|
||||||
|
Result nsa = new Result("NotSA", new byte[]{}, new ResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||||
|
nsa.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||||
|
|
||||||
|
List<Result> inputs = new ArrayList<>();
|
||||||
|
inputs.add(sa3);
|
||||||
|
inputs.add(sa1);
|
||||||
|
inputs.add(nsa);
|
||||||
|
inputs.add(sa2);
|
||||||
|
|
||||||
|
List<Result> results = QRCodeMultiReader.processStructuredAppend(inputs);
|
||||||
|
assertNotNull(results);
|
||||||
|
assertEquals(2, results.size());
|
||||||
|
|
||||||
|
Collection<String> barcodeContents = new HashSet<>();
|
||||||
|
for (Result result : results) {
|
||||||
|
barcodeContents.add(result.getText());
|
||||||
|
}
|
||||||
|
Collection<String> expectedContents = new HashSet<>();
|
||||||
|
expectedContents.add("SA1SA2SA3");
|
||||||
|
expectedContents.add("NotSA");
|
||||||
|
assertEquals(expectedContents, barcodeContents);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue