use of com.google.zxing.NotFoundException in project zxing by zxing.
the class RSSExpandedInternalTestCase method testFindFinderPatterns.
@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
}
}
use of com.google.zxing.NotFoundException in project zxing by zxing.
the class RSSExpandedStackedInternalTestCase method testDecodingRowByRow.
@Test
public void testDecodingRowByRow() throws Exception {
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
BinaryBitmap binaryMap = TestCaseUtil.getBinaryBitmap("src/test/resources/blackbox/rssexpandedstacked-2/1000.png");
int firstRowNumber = binaryMap.getHeight() / 3;
BitArray firstRow = binaryMap.getBlackRow(firstRowNumber, null);
try {
rssExpandedReader.decodeRow2pairs(firstRowNumber, firstRow);
fail(NotFoundException.class.getName() + " expected");
} catch (NotFoundException nfe) {
// ok
}
assertEquals(1, rssExpandedReader.getRows().size());
ExpandedRow firstExpandedRow = rssExpandedReader.getRows().get(0);
assertEquals(firstRowNumber, firstExpandedRow.getRowNumber());
assertEquals(2, firstExpandedRow.getPairs().size());
firstExpandedRow.getPairs().get(1).getFinderPattern().getStartEnd()[1] = 0;
int secondRowNumber = 2 * binaryMap.getHeight() / 3;
BitArray secondRow = binaryMap.getBlackRow(secondRowNumber, null);
secondRow.reverse();
List<ExpandedPair> totalPairs = rssExpandedReader.decodeRow2pairs(secondRowNumber, secondRow);
Result result = RSSExpandedReader.constructResult(totalPairs);
assertEquals("(01)98898765432106(3202)012345(15)991231", result.getText());
}
use of com.google.zxing.NotFoundException in project zxing by zxing.
the class Detector method getMatrixCenter.
/**
* Finds a candidate center point of an Aztec code from an image
*
* @return the center point
*/
private Point getMatrixCenter() {
ResultPoint pointA;
ResultPoint pointB;
ResultPoint pointC;
ResultPoint pointD;
//Get a white rectangle that can be the border of the matrix in center bull's eye or
try {
ResultPoint[] cornerPoints = new WhiteRectangleDetector(image).detect();
pointA = cornerPoints[0];
pointB = cornerPoints[1];
pointC = cornerPoints[2];
pointD = cornerPoints[3];
} catch (NotFoundException e) {
// This exception can be in case the initial rectangle is white
// In that case, surely in the bull's eye, we try to expand the rectangle.
int cx = image.getWidth() / 2;
int cy = image.getHeight() / 2;
pointA = getFirstDifferent(new Point(cx + 7, cy - 7), false, 1, -1).toResultPoint();
pointB = getFirstDifferent(new Point(cx + 7, cy + 7), false, 1, 1).toResultPoint();
pointC = getFirstDifferent(new Point(cx - 7, cy + 7), false, -1, 1).toResultPoint();
pointD = getFirstDifferent(new Point(cx - 7, cy - 7), false, -1, -1).toResultPoint();
}
//Compute the center of the rectangle
int cx = MathUtils.round((pointA.getX() + pointD.getX() + pointB.getX() + pointC.getX()) / 4.0f);
int cy = MathUtils.round((pointA.getY() + pointD.getY() + pointB.getY() + pointC.getY()) / 4.0f);
// in order to compute a more accurate center.
try {
ResultPoint[] cornerPoints = new WhiteRectangleDetector(image, 15, cx, cy).detect();
pointA = cornerPoints[0];
pointB = cornerPoints[1];
pointC = cornerPoints[2];
pointD = cornerPoints[3];
} catch (NotFoundException e) {
// This exception can be in case the initial rectangle is white
// In that case we try to expand the rectangle.
pointA = getFirstDifferent(new Point(cx + 7, cy - 7), false, 1, -1).toResultPoint();
pointB = getFirstDifferent(new Point(cx + 7, cy + 7), false, 1, 1).toResultPoint();
pointC = getFirstDifferent(new Point(cx - 7, cy + 7), false, -1, 1).toResultPoint();
pointD = getFirstDifferent(new Point(cx - 7, cy - 7), false, -1, -1).toResultPoint();
}
// Recompute the center of the rectangle
cx = MathUtils.round((pointA.getX() + pointD.getX() + pointB.getX() + pointC.getX()) / 4.0f);
cy = MathUtils.round((pointA.getY() + pointD.getY() + pointB.getY() + pointC.getY()) / 4.0f);
return new Point(cx, cy);
}
use of com.google.zxing.NotFoundException in project zxing by zxing.
the class RSS14Reader method decodePair.
private Pair decodePair(BitArray row, boolean right, int rowNumber, Map<DecodeHintType, ?> hints) {
try {
int[] startEnd = findFinderPattern(row, right);
FinderPattern pattern = parseFoundFinderPattern(row, rowNumber, right, startEnd);
ResultPointCallback resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
if (resultPointCallback != null) {
float center = (startEnd[0] + startEnd[1]) / 2.0f;
if (right) {
// row is actually reversed
center = row.getSize() - 1 - center;
}
resultPointCallback.foundPossibleResultPoint(new ResultPoint(center, rowNumber));
}
DataCharacter outside = decodeDataCharacter(row, pattern, true);
DataCharacter inside = decodeDataCharacter(row, pattern, false);
return new Pair(1597 * outside.getValue() + inside.getValue(), outside.getChecksumPortion() + 4 * inside.getChecksumPortion(), pattern);
} catch (NotFoundException ignored) {
return null;
}
}
use of com.google.zxing.NotFoundException in project zxing by zxing.
the class RSSExpandedReader method checkRows.
// Try to construct a valid rows sequence
// Recursion is used to implement backtracking
private List<ExpandedPair> checkRows(List<ExpandedRow> collectedRows, int currentRow) throws NotFoundException {
for (int i = currentRow; i < rows.size(); i++) {
ExpandedRow row = rows.get(i);
this.pairs.clear();
for (ExpandedRow collectedRow : collectedRows) {
this.pairs.addAll(collectedRow.getPairs());
}
this.pairs.addAll(row.getPairs());
if (!isValidSequence(this.pairs)) {
continue;
}
if (checkChecksum()) {
return this.pairs;
}
List<ExpandedRow> rs = new ArrayList<>();
rs.addAll(collectedRows);
rs.add(row);
try {
// Recursion: try to add more rows
return checkRows(rs, i + 1);
} catch (NotFoundException e) {
// We failed, try the next candidate
}
}
throw NotFoundException.getNotFoundInstance();
}
Aggregations