Java 类com.google.zxing.BufferedImageLuminanceSource 实例源码

项目:zxing-bsplus    文件:RSSExpandedImage2binaryTestCase.java   
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());
}
项目:zxing-bsplus    文件:RSSExpandedInternalTestCase.java   
@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());
}
项目:zxing-bsplus    文件:RSSExpandedInternalTestCase.java   
@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);

  int[] startEnd = {145, 243};//image pixels where the A1 pattern starts (at 124) and ends (at 214)
  int value = 0; // A
  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());
}
项目:zxing-bsplus    文件:RSSExpandedImage2stringTestCase.java   
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());
}
项目:zxing-bsplus    文件:RSSExpandedImage2resultTestCase.java   
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);
}
项目:zxing-bsplus    文件:MultiTestCase.java   
@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());
}
项目:dev    文件:RSSExpandedImage2binaryTestCase.java   
private static void assertCorrectImage2binary(String path, String expected) throws IOException, NotFoundException {
  RSSExpandedReader rssExpandedReader = new RSSExpandedReader();

  File file = new File(path);
  if (!file.exists()) {
    // Support running from project root too
    file = new File("core", path);
  }

  BufferedImage image = ImageIO.read(file);
  BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
  int rowNumber = binaryMap.getHeight() / 2;
  BitArray row = binaryMap.getBlackRow(rowNumber, null);

  List<ExpandedPair> pairs = rssExpandedReader.decodeRow2pairs(rowNumber, row);
  BitArray binary = BitArrayBuilder.buildBitArray(pairs);
  assertEquals(expected, binary.toString());
}
项目:dev    文件:RSSExpandedInternalTestCase.java   
@Test
public void testDecodeCheckCharacter() throws Exception {
  RSSExpandedReader rssExpandedReader = new RSSExpandedReader();

  String path = "test/data/blackbox/rssexpanded-1/3.jpg";
  File file = new File(path);
  if (!file.exists()) {
    // Support running from project root too
    file = new File("core", path);
  }

  BufferedImage image = ImageIO.read(file);
  BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
  BitArray row = binaryMap.getBlackRow(binaryMap.getHeight() / 2, null);

  int[] startEnd = {145, 243};//image pixels where the A1 pattern starts (at 124) and ends (at 214)
  int value = 0;// A
  FinderPattern finderPatternA1 = new FinderPattern(value, startEnd, startEnd[0], startEnd[1], image.getHeight() / 2);
  //{1, 8, 4, 1, 1};
  DataCharacter dataCharacter = rssExpandedReader.decodeDataCharacter(row, finderPatternA1, true, true);

  assertEquals(98, dataCharacter.getValue());
}
项目:dev    文件:RSSExpandedInternalTestCase.java   
@Test
public void testDecodeDataCharacter() throws Exception {
  RSSExpandedReader rssExpandedReader = new RSSExpandedReader();

  String path = "test/data/blackbox/rssexpanded-1/3.jpg";
  File file = new File(path);
  if (!file.exists()) {
    // Support running from project root too
    file = new File("core", path);
  }

  BufferedImage image = ImageIO.read(file);
  BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
  BitArray row = binaryMap.getBlackRow(binaryMap.getHeight() / 2, null);

  int[] startEnd = {145, 243};//image pixels where the A1 pattern starts (at 124) and ends (at 214)
  int value = 0; // A
  FinderPattern finderPatternA1 = new FinderPattern(value, startEnd, startEnd[0], startEnd[1], image.getHeight() / 2);
  //{1, 8, 4, 1, 1};
  DataCharacter dataCharacter = rssExpandedReader.decodeDataCharacter(row, finderPatternA1, true, false);

  assertEquals(19, dataCharacter.getValue());
  assertEquals(1007, dataCharacter.getChecksumPortion());
}
项目:dev    文件:RSSExpandedImage2stringTestCase.java   
private static void assertCorrectImage2string(String path, String expected) throws IOException, NotFoundException {
  RSSExpandedReader rssExpandedReader = new RSSExpandedReader();

  File file = new File(path);
  if (!file.exists()) {
    // Support running from project root too
    file = new File("core", path);
  }

  BufferedImage image = ImageIO.read(file);
  BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
  int rowNumber = binaryMap.getHeight() / 2;
  BitArray row = binaryMap.getBlackRow(rowNumber, null);

  Result result = rssExpandedReader.decodeRow(rowNumber, row, null);

  assertSame(BarcodeFormat.RSS_EXPANDED, result.getBarcodeFormat());
  assertEquals(expected, result.getText());
}
项目:dev    文件:RSSExpandedImage2resultTestCase.java   
private static void assertCorrectImage2result(String path, ExpandedProductParsedResult expected)
    throws IOException, NotFoundException {
  RSSExpandedReader rssExpandedReader = new RSSExpandedReader();

  File file = new File(path);
  if (!file.exists()) {
    // Support running from project root too
    file = new File("core", path);
  }

  BufferedImage image = ImageIO.read(file);
  BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
  int rowNumber = binaryMap.getHeight() / 2;
  BitArray row = binaryMap.getBlackRow(rowNumber, null);

  Result theResult = rssExpandedReader.decodeRow(rowNumber, row, null);

  assertSame(BarcodeFormat.RSS_EXPANDED, theResult.getBarcodeFormat());

  ParsedResult result = ResultParser.parseResult(theResult);

  assertEquals(expected, result);
}
项目:ZxingCore    文件:RSSExpandedImage2binaryTestCase.java   
private static void assertCorrectImage2binary(String path, String expected) throws IOException, NotFoundException {

    File file = new File(path);
    if (!file.exists()) {
      // Support running from project root too
      file = new File("core", path);
    }

    BufferedImage image = ImageIO.read(file);
    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());
  }
项目:ZxingCore    文件:RSSExpandedInternalTestCase.java   
@Test
public void testDecodeCheckCharacter() throws Exception {

  String path = "test/data/blackbox/rssexpanded-1/3.png";
  File file = new File(path);
  if (!file.exists()) {
    // Support running from project root too
    file = new File("core", path);
  }

  BufferedImage image = ImageIO.read(file);
  BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
  BitArray row = binaryMap.getBlackRow(binaryMap.getHeight() / 2, null);

  int[] startEnd = {145, 243};//image pixels where the A1 pattern starts (at 124) and ends (at 214)
  int value = 0;// A
  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());
}
项目:ZxingCore    文件:RSSExpandedInternalTestCase.java   
@Test
public void testDecodeDataCharacter() throws Exception {

  String path = "test/data/blackbox/rssexpanded-1/3.png";
  File file = new File(path);
  if (!file.exists()) {
    // Support running from project root too
    file = new File("core", path);
  }

  BufferedImage image = ImageIO.read(file);
  BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
  BitArray row = binaryMap.getBlackRow(binaryMap.getHeight() / 2, null);

  int[] startEnd = {145, 243};//image pixels where the A1 pattern starts (at 124) and ends (at 214)
  int value = 0; // A
  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());
}
项目:ZxingCore    文件:RSSExpandedImage2stringTestCase.java   
private static void assertCorrectImage2string(String path, String expected) throws IOException, NotFoundException {

    File file = new File(path);
    if (!file.exists()) {
      // Support running from project root too
      file = new File("core", path);
    }

    BufferedImage image = ImageIO.read(file);
    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());
  }
项目:zxing-bsplus    文件:RSSExpandedInternalTestCase.java   
@Test
public void testFindFinderPatterns() throws Exception {
  BufferedImage image = readImage("2.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(1, finderPattern.getValue());

  ExpandedPair pair3 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
  previousPairs.add(pair3);
  finderPattern = pair3.getFinderPattern();
  assertNotNull(finderPattern);
  assertEquals(1, finderPattern.getValue());

  try{
    rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
    //   the previous was the last pair
    fail(NotFoundException.class.getName() + " expected");
  } catch (NotFoundException nfe) {
    // ok
  }
}
项目:zxing-bsplus    文件:RSSExpandedInternalTestCase.java   
@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);

  int[] startEnd = {145, 243};//image pixels where the A1 pattern starts (at 124) and ends (at 214)
  int value = 0;// A
  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());
}
项目:zxing-bsplus    文件:MultiQRCodeTestCase.java   
@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);
}
项目:dev    文件:RSSExpandedInternalTestCase.java   
@Test
public void testRetrieveNextPairPatterns() throws Exception {
  RSSExpandedReader rssExpandedReader = new RSSExpandedReader();

  String path = "test/data/blackbox/rssexpanded-1/3.jpg";
  File file = new File(path);
  if (!file.exists()) {
    // Support running from project root too
    file = new File("core", path);
  }

  BufferedImage image = ImageIO.read(file);
  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<ExpandedPair>();

  ExpandedPair pair1 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
  previousPairs.add(pair1);
  FinderPattern finderPattern = pair1.getFinderPattern();
  assertNotNull(finderPattern);
  assertEquals(0, finderPattern.getValue());
  assertFalse(pair1.mayBeLast());

  ExpandedPair pair2 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
  previousPairs.add(pair2);
  finderPattern = pair2.getFinderPattern();
  assertNotNull(finderPattern);
  assertEquals(0, finderPattern.getValue());
  assertTrue(pair2.mayBeLast());
}
项目:ZxingCore    文件:RSSExpandedInternalTestCase.java   
@Test
public void testRetrieveNextPairPatterns() throws Exception {

  String path = "test/data/blackbox/rssexpanded-1/3.png";
  File file = new File(path);
  if (!file.exists()) {
    // Support running from project root too
    file = new File("core", path);
  }

  BufferedImage image = ImageIO.read(file);
  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<ExpandedPair>();

  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());
}
项目:ZxingCore    文件:RSSExpandedImage2resultTestCase.java   
private static void assertCorrectImage2result(String path, ExpandedProductParsedResult expected)
    throws IOException, NotFoundException {

  File file = new File(path);
  if (!file.exists()) {
    // Support running from project root too
    file = new File("core", path);
  }

  BufferedImage image = ImageIO.read(file);
  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);
}
项目:zxing-bsplus    文件:TestCaseUtil.java   
static BinaryBitmap getBinaryBitmap(String path) throws IOException {
  BufferedImage bufferedImage = getBufferedImage(path);
  BufferedImageLuminanceSource luminanceSource = new BufferedImageLuminanceSource(bufferedImage);
  return new BinaryBitmap(new GlobalHistogramBinarizer(luminanceSource));
}
项目:dev    文件:RSSExpandedInternalTestCase.java   
@Test
public void testFindFinderPatterns() throws Exception {
  RSSExpandedReader rssExpandedReader = new RSSExpandedReader();

  String path = "test/data/blackbox/rssexpanded-1/2.jpg";
  File file = new File(path);
  if (!file.exists()) {
    // Support running from project root too
    file = new File("core", path);
  }

  BufferedImage image = ImageIO.read(file);
  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<ExpandedPair>();

  ExpandedPair pair1 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
  previousPairs.add(pair1);
  FinderPattern finderPattern = pair1.getFinderPattern();
  assertNotNull(finderPattern);
  assertEquals(0, finderPattern.getValue());
  assertFalse(pair1.mayBeLast());

  ExpandedPair pair2 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
  previousPairs.add(pair2);
  finderPattern = pair2.getFinderPattern();
  assertNotNull(finderPattern);
  assertEquals(1, finderPattern.getValue());
  assertFalse(pair2.mayBeLast());

  ExpandedPair pair3 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
  previousPairs.add(pair3);
  finderPattern = pair3.getFinderPattern();
  assertNotNull(finderPattern);
  assertEquals(1, finderPattern.getValue());
  assertTrue(pair3.mayBeLast());

  try{
    rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
    //   the previous was the last pair
    fail(NotFoundException.class.getName() + " expected");
  }catch(NotFoundException nfe){
    // ok
  }
}
项目:ZxingCore    文件:RSSExpandedInternalTestCase.java   
@Test
public void testFindFinderPatterns() throws Exception {

  String path = "test/data/blackbox/rssexpanded-1/2.png";
  File file = new File(path);
  if (!file.exists()) {
    // Support running from project root too
    file = new File("core", path);
  }

  BufferedImage image = ImageIO.read(file);
  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<ExpandedPair>();

  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(1, finderPattern.getValue());

  ExpandedPair pair3 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
  previousPairs.add(pair3);
  finderPattern = pair3.getFinderPattern();
  assertNotNull(finderPattern);
  assertEquals(1, finderPattern.getValue());

  try{
    rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
    //   the previous was the last pair
    fail(NotFoundException.class.getName() + " expected");
  }catch(NotFoundException nfe){
    // ok
  }
}
项目:ZxingCore    文件:TestCaseUtil.java   
static BinaryBitmap getBinaryBitmap(String path) throws IOException {
    BufferedImage bufferedImage = getBufferedImage(path);
    BufferedImageLuminanceSource luminanceSource = new BufferedImageLuminanceSource(bufferedImage);
    return new BinaryBitmap(new GlobalHistogramBinarizer(luminanceSource));
}