Search in sources :

Example 6 with GlobalHistogramBinarizer

use of com.google.zxing.common.GlobalHistogramBinarizer in project zxing by zxing.

the class RSSExpandedImage2stringTestCase method assertCorrectImage2string.

private static void assertCorrectImage2string(String fileName, String expected) throws IOException, NotFoundException {
    Path path = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/rssexpanded-1/").resolve(fileName);
    BufferedImage image = ImageIO.read(path.toFile());
    BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
    int rowNumber = binaryMap.getHeight() / 2;
    BitArray row = binaryMap.getBlackRow(rowNumber, null);
    Result result;
    try {
        RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
        result = rssExpandedReader.decodeRow(rowNumber, row, null);
    } catch (ReaderException re) {
        fail(re.toString());
        return;
    }
    assertSame(BarcodeFormat.RSS_EXPANDED, result.getBarcodeFormat());
    assertEquals(expected, result.getText());
}
Also used : Path(java.nio.file.Path) GlobalHistogramBinarizer(com.google.zxing.common.GlobalHistogramBinarizer) BufferedImageLuminanceSource(com.google.zxing.BufferedImageLuminanceSource) BitArray(com.google.zxing.common.BitArray) BinaryBitmap(com.google.zxing.BinaryBitmap) BufferedImage(java.awt.image.BufferedImage) Result(com.google.zxing.Result) ReaderException(com.google.zxing.ReaderException)

Example 7 with GlobalHistogramBinarizer

use of com.google.zxing.common.GlobalHistogramBinarizer in project zxing by zxing.

the class RSSExpandedInternalTestCase method testDecodeDataCharacter.

@Test
public void testDecodeDataCharacter() 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, false);
    assertEquals(19, dataCharacter.getValue());
    assertEquals(1007, dataCharacter.getChecksumPortion());
}
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 8 with GlobalHistogramBinarizer

use of com.google.zxing.common.GlobalHistogramBinarizer in project zxing by zxing.

the class TestCaseUtil method getBinaryBitmap.

static BinaryBitmap getBinaryBitmap(String path) throws IOException {
    BufferedImage bufferedImage = getBufferedImage(path);
    BufferedImageLuminanceSource luminanceSource = new BufferedImageLuminanceSource(bufferedImage);
    return new BinaryBitmap(new GlobalHistogramBinarizer(luminanceSource));
}
Also used : GlobalHistogramBinarizer(com.google.zxing.common.GlobalHistogramBinarizer) BufferedImageLuminanceSource(com.google.zxing.BufferedImageLuminanceSource) BinaryBitmap(com.google.zxing.BinaryBitmap) BufferedImage(java.awt.image.BufferedImage)

Example 9 with GlobalHistogramBinarizer

use of com.google.zxing.common.GlobalHistogramBinarizer 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 10 with GlobalHistogramBinarizer

use of com.google.zxing.common.GlobalHistogramBinarizer 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)10 GlobalHistogramBinarizer (com.google.zxing.common.GlobalHistogramBinarizer)10 BufferedImageLuminanceSource (com.google.zxing.BufferedImageLuminanceSource)8 BufferedImage (java.awt.image.BufferedImage)8 BitArray (com.google.zxing.common.BitArray)7 ReaderException (com.google.zxing.ReaderException)4 Result (com.google.zxing.Result)4 FinderPattern (com.google.zxing.oned.rss.FinderPattern)4 Test (org.junit.Test)4 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 MultiFormatReader (com.google.zxing.MultiFormatReader)2 HybridBinarizer (com.google.zxing.common.HybridBinarizer)2 DataCharacter (com.google.zxing.oned.rss.DataCharacter)2 ChecksumException (com.google.zxing.ChecksumException)1 FormatException (com.google.zxing.FormatException)1 LuminanceSource (com.google.zxing.LuminanceSource)1 NotFoundException (com.google.zxing.NotFoundException)1 RGBLuminanceSource (com.google.zxing.RGBLuminanceSource)1 Reader (com.google.zxing.Reader)1