use of com.google.zxing.BinaryBitmap in project zxing by zxing.
the class AbstractNegativeBlackBoxTestCase method checkForFalsePositives.
/**
* Make sure ZXing does NOT find a barcode in the image.
*
* @param image The image to test
* @param rotationInDegrees The amount of rotation to apply
* @return true if nothing found, false if a non-existent barcode was detected
*/
private boolean checkForFalsePositives(BufferedImage image, float rotationInDegrees) {
BufferedImage rotatedImage = rotateImage(image, rotationInDegrees);
LuminanceSource source = new BufferedImageLuminanceSource(rotatedImage);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result result;
try {
result = getReader().decode(bitmap);
log.info(String.format("Found false positive: '%s' with format '%s' (rotation: %d)", result.getText(), result.getBarcodeFormat(), (int) rotationInDegrees));
return false;
} catch (ReaderException re) {
// continue
}
// Try "try harder" getMode
Map<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
try {
result = getReader().decode(bitmap, hints);
log.info(String.format("Try harder found false positive: '%s' with format '%s' (rotation: %d)", result.getText(), result.getBarcodeFormat(), (int) rotationInDegrees));
return false;
} catch (ReaderException re) {
// continue
}
return true;
}
use of com.google.zxing.BinaryBitmap in project zxing by zxing.
the class RSSExpandedImage2binaryTestCase method assertCorrectImage2binary.
private static void assertCorrectImage2binary(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);
List<ExpandedPair> pairs;
try {
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
pairs = rssExpandedReader.decodeRow2pairs(rowNumber, row);
} catch (ReaderException re) {
fail(re.toString());
return;
}
BitArray binary = BitArrayBuilder.buildBitArray(pairs);
assertEquals(expected, binary.toString());
}
use of com.google.zxing.BinaryBitmap in project zxing by zxing.
the class RSSExpandedImage2resultTestCase method assertCorrectImage2result.
private static void assertCorrectImage2result(String fileName, ExpandedProductParsedResult 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 theResult;
try {
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
theResult = rssExpandedReader.decodeRow(rowNumber, row, null);
} catch (ReaderException re) {
fail(re.toString());
return;
}
assertSame(BarcodeFormat.RSS_EXPANDED, theResult.getBarcodeFormat());
ParsedResult result = ResultParser.parseResult(theResult);
assertEquals(expected, result);
}
use of com.google.zxing.BinaryBitmap 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.BinaryBitmap in project zxing by zxing.
the class MultiTestCase method testMulti.
@Test
public void testMulti() throws Exception {
// Very basic test for now
Path testBase = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/multi-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 GenericMultipleBarcodeReader(new MultiFormatReader());
Result[] results = reader.decodeMultiple(bitmap);
assertNotNull(results);
assertEquals(2, results.length);
assertEquals("031415926531", results[0].getText());
assertEquals(BarcodeFormat.UPC_A, results[0].getBarcodeFormat());
assertEquals("www.airtable.com/jobs", results[1].getText());
assertEquals(BarcodeFormat.QR_CODE, results[1].getBarcodeFormat());
}
Aggregations