use of com.google.zxing.BufferedImageLuminanceSource in project zxing by zxing.
the class MultiQRCodeTestCase method testMultiQRCodes.
@Test
public void testMultiQRCodes() throws Exception {
// Very basic test for now
Path testBase = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/multi-qrcode-1");
Path testImage = testBase.resolve("1.png");
BufferedImage image = ImageIO.read(testImage.toFile());
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
MultipleBarcodeReader reader = new QRCodeMultiReader();
Result[] results = reader.decodeMultiple(bitmap);
assertNotNull(results);
assertEquals(4, results.length);
Set<String> barcodeContents = new HashSet<>();
for (Result result : results) {
barcodeContents.add(result.getText());
assertEquals(BarcodeFormat.QR_CODE, result.getBarcodeFormat());
Map<ResultMetadataType, Object> metadata = result.getResultMetadata();
assertNotNull(metadata);
}
Set<String> expectedContents = new HashSet<>();
expectedContents.add("You earned the class a 5 MINUTE DANCE PARTY!! Awesome! Way to go! Let's boogie!");
expectedContents.add("You earned the class 5 EXTRA MINUTES OF RECESS!! Fabulous!! Way to go!!");
expectedContents.add("You get to SIT AT MRS. SIGMON'S DESK FOR A DAY!! Awesome!! Way to go!! Guess I better clean up! :)");
expectedContents.add("You get to CREATE OUR JOURNAL PROMPT FOR THE DAY! Yay! Way to go! ");
assertEquals(expectedContents, barcodeContents);
}
use of com.google.zxing.BufferedImageLuminanceSource in project zxing by zxing.
the class RSSExpandedInternalTestCase method testDecodeCheckCharacter.
@Test
public void testDecodeCheckCharacter() throws Exception {
BufferedImage image = readImage("3.png");
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
BitArray row = binaryMap.getBlackRow(binaryMap.getHeight() / 2, null);
//image pixels where the A1 pattern starts (at 124) and ends (at 214)
int[] startEnd = { 145, 243 };
// A
int value = 0;
FinderPattern finderPatternA1 = new FinderPattern(value, startEnd, startEnd[0], startEnd[1], image.getHeight() / 2);
//{1, 8, 4, 1, 1};
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
DataCharacter dataCharacter = rssExpandedReader.decodeDataCharacter(row, finderPatternA1, true, true);
assertEquals(98, dataCharacter.getValue());
}
use of com.google.zxing.BufferedImageLuminanceSource in project zxing by zxing.
the class RSSExpandedInternalTestCase method testRetrieveNextPairPatterns.
@Test
public void testRetrieveNextPairPatterns() throws Exception {
BufferedImage image = readImage("3.png");
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
int rowNumber = binaryMap.getHeight() / 2;
BitArray row = binaryMap.getBlackRow(rowNumber, null);
List<ExpandedPair> previousPairs = new ArrayList<>();
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
ExpandedPair pair1 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
previousPairs.add(pair1);
FinderPattern finderPattern = pair1.getFinderPattern();
assertNotNull(finderPattern);
assertEquals(0, finderPattern.getValue());
ExpandedPair pair2 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
previousPairs.add(pair2);
finderPattern = pair2.getFinderPattern();
assertNotNull(finderPattern);
assertEquals(0, finderPattern.getValue());
}
Aggregations