public ResultPoint[] detect() throws NotFoundException {

    int left = leftInit;
    int right = rightInit;
    int up = upInit;
    int down = downInit;
    boolean sizeExceeded = false;
    boolean aBlackPointFoundOnBorder = true;

    boolean atLeastOneBlackPointFoundOnRight = false;
    boolean atLeastOneBlackPointFoundOnBottom = false;
    boolean atLeastOneBlackPointFoundOnLeft = false;
    boolean atLeastOneBlackPointFoundOnTop = false;

    while (aBlackPointFoundOnBorder) {

      aBlackPointFoundOnBorder = false;

      // .....
      // .   |
      // .....
      boolean rightBorderNotWhite = true;
      while ((rightBorderNotWhite || !atLeastOneBlackPointFoundOnRight) && right < width) {
        rightBorderNotWhite = containsBlackPoint(up, down, right, false);
        if (rightBorderNotWhite) {
          right++;
          aBlackPointFoundOnBorder = true;
          atLeastOneBlackPointFoundOnRight = true;
        } else if (!atLeastOneBlackPointFoundOnRight) {
          right++;
        }
      }

      if (right >= width) {
        sizeExceeded = true;
        break;
      }

      // .....
      // .   .
      // .___.
      boolean bottomBorderNotWhite = true;
      while ((bottomBorderNotWhite || !atLeastOneBlackPointFoundOnBottom) && down < height) {
        bottomBorderNotWhite = containsBlackPoint(left, right, down, true);
        if (bottomBorderNotWhite) {
          down++;
          aBlackPointFoundOnBorder = true;
          atLeastOneBlackPointFoundOnBottom = true;
        } else if (!atLeastOneBlackPointFoundOnBottom) {
          down++;
        }
      }

      if (down >= height) {
        sizeExceeded = true;
        break;
      }

      // .....
      // |   .
      // .....
      boolean leftBorderNotWhite = true;
      while ((leftBorderNotWhite || !atLeastOneBlackPointFoundOnLeft) && left >= 0) {
        leftBorderNotWhite = containsBlackPoint(up, down, left, false);
        if (leftBorderNotWhite) {
          left--;
          aBlackPointFoundOnBorder = true;
          atLeastOneBlackPointFoundOnLeft = true;
        } else if (!atLeastOneBlackPointFoundOnLeft) {
          left--;
        }
      }

      if (left < 0) {
        sizeExceeded = true;
        break;
      }

      // .___.
      // .   .
      // .....
      boolean topBorderNotWhite = true;
      while ((topBorderNotWhite || !atLeastOneBlackPointFoundOnTop) && up >= 0) {
        topBorderNotWhite = containsBlackPoint(left, right, up, true);
        if (topBorderNotWhite) {
          up--;
          aBlackPointFoundOnBorder = true;
          atLeastOneBlackPointFoundOnTop = true;
        } else if (!atLeastOneBlackPointFoundOnTop) {
          up--;
        }
      }

      if (up < 0) {
        sizeExceeded = true;
        break;
      }

    }

    if (!sizeExceeded) {

      int maxSize = right - left;

      ResultPoint z = null;
      for (int i = 1; z == null && i < maxSize; i++) {
        z = getBlackPointOnSegment(left, down - i, left + i, down);
      }

      if (z == null) {
        throw NotFoundException.getNotFoundInstance();
      }

      ResultPoint t = null;
      //go down right
      for (int i = 1; t == null && i < maxSize; i++) {
        t = getBlackPointOnSegment(left, up + i, left + i, up);
      }

      if (t == null) {
        throw NotFoundException.getNotFoundInstance();
      }

      ResultPoint x = null;
      //go down left
      for (int i = 1; x == null && i < maxSize; i++) {
        x = getBlackPointOnSegment(right, up + i, right - i, up);
      }

      if (x == null) {
        throw NotFoundException.getNotFoundInstance();
      }

      ResultPoint y = null;
      //go up left
      for (int i = 1; y == null && i < maxSize; i++) {
        y = getBlackPointOnSegment(right, down - i, right - i, down);
      }

      if (y == null) {
        throw NotFoundException.getNotFoundInstance();
      }

      return centerEdges(y, z, x, t);

    } else {
      throw NotFoundException.getNotFoundInstance();
    }
  }
public ResultPoint [ ] detect ( ) throws NotFoundException { int left = leftInit ; int right = rightInit ; int up = upInit ; int down = downInit ; boolean sizeExceeded = false ; boolean aBlackPointFoundOnBorder = true ; boolean atLeastOneBlackPointFoundOnRight = false ; boolean atLeastOneBlackPointFoundOnBottom = false ; boolean atLeastOneBlackPointFoundOnLeft = false ; boolean atLeastOneBlackPointFoundOnTop = false ; while ( aBlackPointFoundOnBorder ) { aBlackPointFoundOnBorder = false ; boolean rightBorderNotWhite = true ; while ( ( rightBorderNotWhite || ! atLeastOneBlackPointFoundOnRight ) && right < width ) { rightBorderNotWhite = containsBlackPoint ( up , down , right , false ) ; if ( rightBorderNotWhite ) { right ++ ; aBlackPointFoundOnBorder = true ; atLeastOneBlackPointFoundOnRight = true ; } else if ( ! atLeastOneBlackPointFoundOnRight ) { right ++ ; } } if ( right >= width ) { sizeExceeded = true ; break ; } boolean bottomBorderNotWhite = true ; while ( ( bottomBorderNotWhite || ! atLeastOneBlackPointFoundOnBottom ) && down < height ) { bottomBorderNotWhite = containsBlackPoint ( left , right , down , true ) ; if ( bottomBorderNotWhite ) { down ++ ; aBlackPointFoundOnBorder = true ; atLeastOneBlackPointFoundOnBottom = true ; } else if ( ! atLeastOneBlackPointFoundOnBottom ) { down ++ ; } } if ( down >= height ) { sizeExceeded = true ; break ; } boolean leftBorderNotWhite = true ; while ( ( leftBorderNotWhite || ! atLeastOneBlackPointFoundOnLeft ) && left >= 0 ) { leftBorderNotWhite = containsBlackPoint ( up , down , left , false ) ; if ( leftBorderNotWhite ) { left -- ; aBlackPointFoundOnBorder = true ; atLeastOneBlackPointFoundOnLeft = true ; } else if ( ! atLeastOneBlackPointFoundOnLeft ) { left -- ; } } if ( left < 0 ) { sizeExceeded = true ; break ; } boolean topBorderNotWhite = true ; while ( ( topBorderNotWhite || ! atLeastOneBlackPointFoundOnTop ) && up >= 0 ) { topBorderNotWhite = containsBlackPoint ( left , right , up , true ) ; if ( topBorderNotWhite ) { up -- ; aBlackPointFoundOnBorder = true ; atLeastOneBlackPointFoundOnTop = true ; } else if ( ! atLeastOneBlackPointFoundOnTop ) { up -- ; } } if ( up < 0 ) { sizeExceeded = true ; break ; } } if ( ! sizeExceeded ) { int maxSize = right - left ; ResultPoint z = null ; for ( int i = 1 ; z == null && i < maxSize ; i ++ ) { z = getBlackPointOnSegment ( left , down - i , left + i , down ) ; } if ( z == null ) { throw NotFoundException . getNotFoundInstance ( ) ; } ResultPoint t = null ; for ( int i = 1 ; t == null && i < maxSize ; i ++ ) { t = getBlackPointOnSegment ( left , up + i , left + i , up ) ; } if ( t == null ) { throw NotFoundException . getNotFoundInstance ( ) ; } ResultPoint x = null ; for ( int i = 1 ; x == null && i < maxSize ; i ++ ) { x = getBlackPointOnSegment ( right , up + i , right - i , up ) ; } if ( x == null ) { throw NotFoundException . getNotFoundInstance ( ) ; } ResultPoint y = null ; for ( int i = 1 ; y == null && i < maxSize ; i ++ ) { y = getBlackPointOnSegment ( right , down - i , right - i , down ) ; } if ( y == null ) { throw NotFoundException . getNotFoundInstance ( ) ; } return centerEdges ( y , z , x , t ) ; } else { throw NotFoundException . getNotFoundInstance ( ) ; } }
<p>
Detects a candidate barcode-like rectangular region within an image. It
starts around the center of the image, increases the size of the candidate
region until it finds a white rectangular region.
</p>

@return {@link ResultPoint}[] describing the corners of the rectangular
region. The first and last points are opposed on the diagonal, as
are the second and third. The first point will be the topmost
point and the last, the bottommost. The second point will be
leftmost and the third, the rightmost
@throws NotFoundException if no Data Matrix Code can be found