public int compare(FinderPattern center1, FinderPattern center2) { float value = center2.getEstimatedModuleSize() - center1.getEstimatedModuleSize(); if (((double) value) < 0.0d) { return -1; } return ((double) value) > 0.0d ? 1 : 0; }
public int a(FinderPattern finderpattern, FinderPattern finderpattern1) { float f = finderpattern1.getEstimatedModuleSize() - finderpattern.getEstimatedModuleSize(); if ((double)f < 0.0D) { return -1; } return (double)f <= 0.0D ? 0 : 1; }
@Override public int compare(FinderPattern center1, FinderPattern center2) { float value = center2.getEstimatedModuleSize() - center1.getEstimatedModuleSize(); return value < 0.0 ? -1 : value > 0.0 ? 1 : 0; }
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]++; } } } // for j=... 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()]); } }
private FinderPattern[][] selectMutipleBestPatterns() throws NotFoundException { List<FinderPattern> possibleCenters = getPossibleCenters(); int size = possibleCenters.size(); if (size < 3) { throw NotFoundException.getNotFoundInstance(); } else if (size == 3) { FinderPattern[][] finderPatternArr = new FinderPattern[1][]; finderPatternArr[0] = new FinderPattern[]{(FinderPattern) possibleCenters.get(0), (FinderPattern) possibleCenters.get(1), (FinderPattern) possibleCenters.get(2)}; return finderPatternArr; } else { Collections.sort(possibleCenters, new ModuleSizeComparator()); List<FinderPattern[]> results = new ArrayList(); for (int i1 = 0; i1 < size - 2; i1++) { FinderPattern p1 = (FinderPattern) possibleCenters.get(i1); if (p1 != null) { for (int i2 = i1 + 1; i2 < size - 1; i2++) { FinderPattern p2 = (FinderPattern) possibleCenters.get(i2); if (p2 != null) { float vModSize12 = (p1.getEstimatedModuleSize() - p2 .getEstimatedModuleSize()) / Math.min(p1 .getEstimatedModuleSize(), p2.getEstimatedModuleSize()); if (Math.abs(p1.getEstimatedModuleSize() - p2.getEstimatedModuleSize ()) > DIFF_MODSIZE_CUTOFF && vModSize12 >= DIFF_MODSIZE_CUTOFF_PERCENT) { break; } for (int i3 = i2 + 1; i3 < size; i3++) { FinderPattern p3 = (FinderPattern) possibleCenters.get(i3); if (p3 != null) { float vModSize23 = (p2.getEstimatedModuleSize() - p3 .getEstimatedModuleSize()) / Math.min(p2 .getEstimatedModuleSize(), p3.getEstimatedModuleSize()); if (Math.abs(p2.getEstimatedModuleSize() - p3 .getEstimatedModuleSize()) > DIFF_MODSIZE_CUTOFF && vModSize23 >= DIFF_MODSIZE_CUTOFF_PERCENT) { break; } Object test = new FinderPattern[]{p1, p2, p3}; ResultPoint.orderBestPatterns(test); FinderPatternInfo info = new FinderPatternInfo(test); float dA = ResultPoint.distance(info.getTopLeft(), info .getBottomLeft()); float dC = ResultPoint.distance(info.getTopRight(), info .getBottomLeft()); float dB = ResultPoint.distance(info.getTopLeft(), info .getTopRight()); float estimatedModuleCount = (dA + dB) / (p1 .getEstimatedModuleSize() * 2.0f); if (estimatedModuleCount <= MAX_MODULE_COUNT_PER_EDGE && estimatedModuleCount >= MIN_MODULE_COUNT_PER_EDGE && Math.abs((dA - dB) / Math.min(dA, dB)) < 0.1f) { float dCpy = (float) Math.sqrt((double) ((dA * dA) + (dB * dB))); if (Math.abs((dC - dCpy) / Math.min(dC, dCpy)) < 0.1f) { results.add(test); } } } } } } } } if (!results.isEmpty()) { return (FinderPattern[][]) results.toArray(new FinderPattern[results.size()][]); } throw NotFoundException.getNotFoundInstance(); } }
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]++; } } } // for j=... 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()]); } }
public FinderPatternInfo[] findMulti(Map<DecodeHintType, ?> hints) throws NotFoundException { boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER); 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)) { // 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]++; } } } // for j=... if (foundPatternCross(stateCount)) { handlePossibleCenter(stateCount, i, maxJ); } // end if foundPatternCross } // for i=iSkip-1 ... FinderPattern[][] patternInfo = selectMutipleBestPatterns(); List<FinderPatternInfo> result = new ArrayList<FinderPatternInfo>(); 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()]); } }