Search in sources :

Example 11 with BufferedImageLuminanceSource

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);
}
Also used : Path(java.nio.file.Path) MultipleBarcodeReader(com.google.zxing.multi.MultipleBarcodeReader) HybridBinarizer(com.google.zxing.common.HybridBinarizer) BufferedImage(java.awt.image.BufferedImage) Result(com.google.zxing.Result) LuminanceSource(com.google.zxing.LuminanceSource) BufferedImageLuminanceSource(com.google.zxing.BufferedImageLuminanceSource) BufferedImageLuminanceSource(com.google.zxing.BufferedImageLuminanceSource) ResultMetadataType(com.google.zxing.ResultMetadataType) BinaryBitmap(com.google.zxing.BinaryBitmap) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with BufferedImageLuminanceSource

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());
}
Also used : GlobalHistogramBinarizer(com.google.zxing.common.GlobalHistogramBinarizer) FinderPattern(com.google.zxing.oned.rss.FinderPattern) BufferedImageLuminanceSource(com.google.zxing.BufferedImageLuminanceSource) BitArray(com.google.zxing.common.BitArray) BinaryBitmap(com.google.zxing.BinaryBitmap) BufferedImage(java.awt.image.BufferedImage) DataCharacter(com.google.zxing.oned.rss.DataCharacter) Test(org.junit.Test)

Example 13 with BufferedImageLuminanceSource

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());
}
Also used : GlobalHistogramBinarizer(com.google.zxing.common.GlobalHistogramBinarizer) FinderPattern(com.google.zxing.oned.rss.FinderPattern) BufferedImageLuminanceSource(com.google.zxing.BufferedImageLuminanceSource) ArrayList(java.util.ArrayList) BitArray(com.google.zxing.common.BitArray) BinaryBitmap(com.google.zxing.BinaryBitmap) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.Test)

Aggregations

BinaryBitmap (com.google.zxing.BinaryBitmap)13 BufferedImageLuminanceSource (com.google.zxing.BufferedImageLuminanceSource)13 BufferedImage (java.awt.image.BufferedImage)13 GlobalHistogramBinarizer (com.google.zxing.common.GlobalHistogramBinarizer)8 BitArray (com.google.zxing.common.BitArray)7 Path (java.nio.file.Path)7 ReaderException (com.google.zxing.ReaderException)6 Result (com.google.zxing.Result)6 Test (org.junit.Test)6 LuminanceSource (com.google.zxing.LuminanceSource)5 FinderPattern (com.google.zxing.oned.rss.FinderPattern)4 HybridBinarizer (com.google.zxing.common.HybridBinarizer)3 ArrayList (java.util.ArrayList)3 DataCharacter (com.google.zxing.oned.rss.DataCharacter)2 DecodeHintType (com.google.zxing.DecodeHintType)1 MultiFormatReader (com.google.zxing.MultiFormatReader)1 NotFoundException (com.google.zxing.NotFoundException)1 ResultMetadataType (com.google.zxing.ResultMetadataType)1 ExpandedProductParsedResult (com.google.zxing.client.result.ExpandedProductParsedResult)1 ParsedResult (com.google.zxing.client.result.ParsedResult)1