Java Code Examples for com.google.zxing.ResultPoint#orderBestPatterns()

The following examples show how to use com.google.zxing.ResultPoint#orderBestPatterns() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiFinderPatternFinder.java    From ScreenCapture with MIT License 4 votes vote down vote up
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()]);
  }
}
 
Example 2
Source File: MultiFinderPatternFinder.java    From Tesseract-OCR-Scanner with Apache License 2.0 4 votes vote down vote up
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()]);
  }
}
 
Example 3
Source File: MultiFinderPatternFinder.java    From QrCodeScanner with GNU General Public License v3.0 4 votes vote down vote up
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()]);
  }
}
 
Example 4
Source File: MultiFinderPatternFinder.java    From ZXing-Orient with Apache License 2.0 4 votes vote down vote up
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()]);
  }
}
 
Example 5
Source File: MultiFinderPatternFinder.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 4 votes vote down vote up
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()]);
  }
}
 
Example 6
Source File: MultiFinderPatternFinder.java    From weex with Apache License 2.0 4 votes vote down vote up
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()]);
  }
}
 
Example 7
Source File: MultiFinderPatternFinder.java    From barcodescanner-lib-aar with MIT License 4 votes vote down vote up
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()]);
  }
}
 
Example 8
Source File: MultiFinderPatternFinder.java    From reacteu-app with MIT License 4 votes vote down vote up
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)) { // Yes
              boolean confirmed = handlePossibleCenter(stateCount, i, j);
              if (!confirmed) {
                do { // Advance to next black pixel
                  j++;
                } while (j < maxJ && !image.get(j, i));
                j--; // back up to that last white pixel
              }
              // 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()]);
  }
}
 
Example 9
Source File: MultiFinderPatternFinder.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
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 = (3 * maxI) / (4 * MAX_MODULES);
  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
    clearCounts(stateCount);
    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;
              clearCounts(stateCount);
            } else { // No, shift counts back by two
              shiftCounts2(stateCount);
              currentState = 3;
            }
          } else {
            stateCount[++currentState]++;
          }
        } else { // Counting white pixels
          stateCount[currentState]++;
        }
      }
    } // for j=...

    if (foundPatternCross(stateCount)) {
      handlePossibleCenter(stateCount, i, maxJ);
    }
  } // for i=iSkip-1 ...
  FinderPattern[][] patternInfo = selectMultipleBestPatterns();
  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(EMPTY_RESULT_ARRAY);
  }
}
 
Example 10
Source File: MultiFinderPatternFinder.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
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 = (3 * maxI) / (4 * MAX_MODULES);
  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
    clearCounts(stateCount);
    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;
              clearCounts(stateCount);
            } else { // No, shift counts back by two
              shiftCounts2(stateCount);
              currentState = 3;
            }
          } else {
            stateCount[++currentState]++;
          }
        } else { // Counting white pixels
          stateCount[currentState]++;
        }
      }
    } // for j=...

    if (foundPatternCross(stateCount)) {
      handlePossibleCenter(stateCount, i, maxJ);
    }
  } // for i=iSkip-1 ...
  FinderPattern[][] patternInfo = selectMultipleBestPatterns();
  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(EMPTY_RESULT_ARRAY);
  }
}