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()); }
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()); }
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); }
@Ignore 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()); }
@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); }
public static void main(String[] args) throws Exception { long now = System.currentTimeMillis(); SummaryResults results = new SummaryResults(); for (AbstractBlackBoxTestCase test : TESTS) { results.add(test.testBlackBoxCountingResults(false)); } now = System.currentTimeMillis() - now; System.out.println(results.toString() + "\n Total time: " + now + " ms"); }
public static void main(String[] args) throws Exception { long start = System.currentTimeMillis(); SummaryResults results = new SummaryResults(); for (AbstractBlackBoxTestCase test : TESTS) { results.add(test.testBlackBoxCountingResults(false)); } log.info(results.toString()); log.info(String.format("Total time: %d ms", System.currentTimeMillis() - start)); }
private static BufferedImage readImage(String fileName) throws IOException { Path path = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/rssexpanded-1/").resolve(fileName); return ImageIO.read(path.toFile()); }
private static BufferedImage getBufferedImage(String path) throws IOException { Path file = AbstractBlackBoxTestCase.buildTestBase(path); return ImageIO.read(file.toFile()); }