use of com.google.zxing.qrcode.detector.FinderPatternInfo in project zxing by zxing.
the class MultiDetector method detectMulti.
public DetectorResult[] detectMulti(Map<DecodeHintType, ?> hints) throws NotFoundException {
BitMatrix image = getImage();
ResultPointCallback resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image, resultPointCallback);
FinderPatternInfo[] infos = finder.findMulti(hints);
if (infos.length == 0) {
throw NotFoundException.getNotFoundInstance();
}
List<DetectorResult> result = new ArrayList<>();
for (FinderPatternInfo info : infos) {
try {
result.add(processFinderPatternInfo(info));
} catch (ReaderException e) {
// ignore
}
}
if (result.isEmpty()) {
return EMPTY_DETECTOR_RESULTS;
} else {
return result.toArray(new DetectorResult[result.size()]);
}
}
use of com.google.zxing.qrcode.detector.FinderPatternInfo in project zxing by zxing.
the class MultiFinderPatternFinder method findMulti.
public FinderPatternInfo[] findMulti(Map<DecodeHintType, ?> hints) throws NotFoundException {
boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);
boolean pureBarcode = hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE);
BitMatrix image = getImage();
int maxI = image.getHeight();
int maxJ = image.getWidth();
// We are looking for black/white/black/white/black modules in
// 1:1:3:1:1 ratio; this tracks the number of such modules seen so far
// Let's assume that the maximum version QR Code we support takes up 1/4 the height of the
// image, and then account for the center being 3 modules in size. This gives the smallest
// number of pixels the center could be, so skip this often. When trying harder, look for all
// QR versions regardless of how dense they are.
int iSkip = (int) (maxI / (MAX_MODULES * 4.0f) * 3);
if (iSkip < MIN_SKIP || tryHarder) {
iSkip = MIN_SKIP;
}
int[] stateCount = new int[5];
for (int i = iSkip - 1; i < maxI; i += iSkip) {
// Get a row of black/white values
stateCount[0] = 0;
stateCount[1] = 0;
stateCount[2] = 0;
stateCount[3] = 0;
stateCount[4] = 0;
int currentState = 0;
for (int j = 0; j < maxJ; j++) {
if (image.get(j, i)) {
// Black pixel
if ((currentState & 1) == 1) {
// Counting white pixels
currentState++;
}
stateCount[currentState]++;
} else {
// White pixel
if ((currentState & 1) == 0) {
// Counting black pixels
if (currentState == 4) {
// A winner?
if (foundPatternCross(stateCount) && handlePossibleCenter(stateCount, i, j, pureBarcode)) {
// Yes
// Clear state to start looking again
currentState = 0;
stateCount[0] = 0;
stateCount[1] = 0;
stateCount[2] = 0;
stateCount[3] = 0;
stateCount[4] = 0;
} else {
// No, shift counts back by two
stateCount[0] = stateCount[2];
stateCount[1] = stateCount[3];
stateCount[2] = stateCount[4];
stateCount[3] = 1;
stateCount[4] = 0;
currentState = 3;
}
} else {
stateCount[++currentState]++;
}
} else {
// Counting white pixels
stateCount[currentState]++;
}
}
}
if (foundPatternCross(stateCount)) {
handlePossibleCenter(stateCount, i, maxJ, pureBarcode);
}
// end if foundPatternCross
}
// for i=iSkip-1 ...
FinderPattern[][] patternInfo = selectMutipleBestPatterns();
List<FinderPatternInfo> result = new ArrayList<>();
for (FinderPattern[] pattern : patternInfo) {
ResultPoint.orderBestPatterns(pattern);
result.add(new FinderPatternInfo(pattern));
}
if (result.isEmpty()) {
return EMPTY_RESULT_ARRAY;
} else {
return result.toArray(new FinderPatternInfo[result.size()]);
}
}
use of com.google.zxing.qrcode.detector.FinderPatternInfo in project weex-example by KalicyZhou.
the class MultiDetector method detectMulti.
public DetectorResult[] detectMulti(Map<DecodeHintType, ?> hints) throws NotFoundException {
BitMatrix image = getImage();
ResultPointCallback resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image, resultPointCallback);
FinderPatternInfo[] infos = finder.findMulti(hints);
if (infos.length == 0) {
throw NotFoundException.getNotFoundInstance();
}
List<DetectorResult> result = new ArrayList<>();
for (FinderPatternInfo info : infos) {
try {
result.add(processFinderPatternInfo(info));
} catch (ReaderException e) {
// ignore
}
}
if (result.isEmpty()) {
return EMPTY_DETECTOR_RESULTS;
} else {
return result.toArray(new DetectorResult[result.size()]);
}
}
use of com.google.zxing.qrcode.detector.FinderPatternInfo in project weex-example by KalicyZhou.
the class MultiFinderPatternFinder method findMulti.
public FinderPatternInfo[] findMulti(Map<DecodeHintType, ?> hints) throws NotFoundException {
boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);
boolean pureBarcode = hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE);
BitMatrix image = getImage();
int maxI = image.getHeight();
int maxJ = image.getWidth();
// We are looking for black/white/black/white/black modules in
// 1:1:3:1:1 ratio; this tracks the number of such modules seen so far
// Let's assume that the maximum version QR Code we support takes up 1/4 the height of the
// image, and then account for the center being 3 modules in size. This gives the smallest
// number of pixels the center could be, so skip this often. When trying harder, look for all
// QR versions regardless of how dense they are.
int iSkip = (int) (maxI / (MAX_MODULES * 4.0f) * 3);
if (iSkip < MIN_SKIP || tryHarder) {
iSkip = MIN_SKIP;
}
int[] stateCount = new int[5];
for (int i = iSkip - 1; i < maxI; i += iSkip) {
// Get a row of black/white values
stateCount[0] = 0;
stateCount[1] = 0;
stateCount[2] = 0;
stateCount[3] = 0;
stateCount[4] = 0;
int currentState = 0;
for (int j = 0; j < maxJ; j++) {
if (image.get(j, i)) {
// Black pixel
if ((currentState & 1) == 1) {
// Counting white pixels
currentState++;
}
stateCount[currentState]++;
} else {
// White pixel
if ((currentState & 1) == 0) {
// Counting black pixels
if (currentState == 4) {
// A winner?
if (foundPatternCross(stateCount) && handlePossibleCenter(stateCount, i, j, pureBarcode)) {
// Yes
// Clear state to start looking again
currentState = 0;
stateCount[0] = 0;
stateCount[1] = 0;
stateCount[2] = 0;
stateCount[3] = 0;
stateCount[4] = 0;
} else {
// No, shift counts back by two
stateCount[0] = stateCount[2];
stateCount[1] = stateCount[3];
stateCount[2] = stateCount[4];
stateCount[3] = 1;
stateCount[4] = 0;
currentState = 3;
}
} else {
stateCount[++currentState]++;
}
} else {
// Counting white pixels
stateCount[currentState]++;
}
}
}
if (foundPatternCross(stateCount)) {
handlePossibleCenter(stateCount, i, maxJ, pureBarcode);
}
// end if foundPatternCross
}
// for i=iSkip-1 ...
FinderPattern[][] patternInfo = selectMutipleBestPatterns();
List<FinderPatternInfo> result = new ArrayList<>();
for (FinderPattern[] pattern : patternInfo) {
ResultPoint.orderBestPatterns(pattern);
result.add(new FinderPatternInfo(pattern));
}
if (result.isEmpty()) {
return EMPTY_RESULT_ARRAY;
} else {
return result.toArray(new FinderPatternInfo[result.size()]);
}
}
use of com.google.zxing.qrcode.detector.FinderPatternInfo in project incubator-weex by apache.
the class MultiFinderPatternFinder method findMulti.
public FinderPatternInfo[] findMulti(Map<DecodeHintType, ?> hints) throws NotFoundException {
boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);
boolean pureBarcode = hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE);
BitMatrix image = getImage();
int maxI = image.getHeight();
int maxJ = image.getWidth();
// We are looking for black/white/black/white/black modules in
// 1:1:3:1:1 ratio; this tracks the number of such modules seen so far
// Let's assume that the maximum version QR Code we support takes up 1/4 the height of the
// image, and then account for the center being 3 modules in size. This gives the smallest
// number of pixels the center could be, so skip this often. When trying harder, look for all
// QR versions regardless of how dense they are.
int iSkip = (int) (maxI / (MAX_MODULES * 4.0f) * 3);
if (iSkip < MIN_SKIP || tryHarder) {
iSkip = MIN_SKIP;
}
int[] stateCount = new int[5];
for (int i = iSkip - 1; i < maxI; i += iSkip) {
// Get a row of black/white values
stateCount[0] = 0;
stateCount[1] = 0;
stateCount[2] = 0;
stateCount[3] = 0;
stateCount[4] = 0;
int currentState = 0;
for (int j = 0; j < maxJ; j++) {
if (image.get(j, i)) {
// Black pixel
if ((currentState & 1) == 1) {
// Counting white pixels
currentState++;
}
stateCount[currentState]++;
} else {
// White pixel
if ((currentState & 1) == 0) {
// Counting black pixels
if (currentState == 4) {
// A winner?
if (foundPatternCross(stateCount) && handlePossibleCenter(stateCount, i, j, pureBarcode)) {
// Yes
// Clear state to start looking again
currentState = 0;
stateCount[0] = 0;
stateCount[1] = 0;
stateCount[2] = 0;
stateCount[3] = 0;
stateCount[4] = 0;
} else {
// No, shift counts back by two
stateCount[0] = stateCount[2];
stateCount[1] = stateCount[3];
stateCount[2] = stateCount[4];
stateCount[3] = 1;
stateCount[4] = 0;
currentState = 3;
}
} else {
stateCount[++currentState]++;
}
} else {
// Counting white pixels
stateCount[currentState]++;
}
}
}
if (foundPatternCross(stateCount)) {
handlePossibleCenter(stateCount, i, maxJ, pureBarcode);
}
// end if foundPatternCross
}
// for i=iSkip-1 ...
FinderPattern[][] patternInfo = selectMutipleBestPatterns();
List<FinderPatternInfo> result = new ArrayList<>();
for (FinderPattern[] pattern : patternInfo) {
ResultPoint.orderBestPatterns(pattern);
result.add(new FinderPatternInfo(pattern));
}
if (result.isEmpty()) {
return EMPTY_RESULT_ARRAY;
} else {
return result.toArray(new FinderPatternInfo[result.size()]);
}
}
Aggregations