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());
}
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());
}
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));
}
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());
}
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());
}
Aggregations