public Optional<Dimension2D> findPaperPattern(Mat mat,List<MatOfPoint2f> patternList){
  MatOfPoint2f boardCorners=null;
  int index=0;
  Optional<Dimension2D> result=Optional.empty();
  for (; index < patternList.size(); index++) {
    boardCorners=patternList.get(index);
    final RotatedRect rect=getPatternDimensions(boardCorners);
    double rect_width=rect.size.width, rect_height=rect.size.height;
    double width=rect_width, height=rect_height;
    if (height > width) {
      width=rect_height;
      height=rect_width;
      rect_height=width;
      rect_width=height;
    }
    width=(width * ((double)(PATTERN_WIDTH + 1) / (double)(PATTERN_WIDTH - 1)) * PAPER_MARGIN_WIDTH);
    height=(height * ((double)(PATTERN_HEIGHT + 1) / (double)(PATTERN_HEIGHT - 1)) * PAPER_MARGIN_HEIGHT);
    final double PAPER_PATTERN_SIZE_THRESHOLD=.25;
    if (width > PAPER_PATTERN_SIZE_THRESHOLD * mat.cols() || height > PAPER_PATTERN_SIZE_THRESHOLD * mat.rows()) {
      continue;
    }
    if (logger.isTraceEnabled()) {
      logger.trace("pattern width {} height {}",rect_width,rect_height);
      logger.trace("paper width {} height {}",width,height);
    }
    final Dimension2D newPaperDimensions=new Dimension2D(width,height);
    result=Optional.of(newPaperDimensions);
    break;
  }
  if (result.isPresent()) {
    logger.trace("Removing paper pattern from patternList (index {})",index);
    patternList.remove(index);
  }
  return result;
}

public Optional < Dimension2D > findPaperPattern ( Mat mat , List < MatOfPoint2f > patternList ) { MatOfPoint2f boardCorners = null ; int index = 0 ; Optional < Dimension2D > result = Optional . empty ( ) ; for ( ; index < patternList . size ( ) ; index ++ ) { boardCorners = patternList . get ( index ) ; final RotatedRect rect = getPatternDimensions ( boardCorners ) ; double rect_width = rect . size . width , rect_height = rect . size . height ; double width = rect_width , height = rect_height ; if ( height > width ) { width = rect_height ; height = rect_width ; rect_height = width ; rect_width = height ; } width = ( width * ( ( double ) ( PATTERN_WIDTH + 1 ) / ( double ) ( PATTERN_WIDTH - 1 ) ) * PAPER_MARGIN_WIDTH ) ; height = ( height * ( ( double ) ( PATTERN_HEIGHT + 1 ) / ( double ) ( PATTERN_HEIGHT - 1 ) ) * PAPER_MARGIN_HEIGHT ) ; final double PAPER_PATTERN_SIZE_THRESHOLD = .25 ; if ( width > PAPER_PATTERN_SIZE_THRESHOLD * mat . cols ( ) || height > PAPER_PATTERN_SIZE_THRESHOLD * mat . rows ( ) ) { continue ; } if ( logger . isTraceEnabled ( ) ) { logger . trace ( "pattern width {} height {}" , rect_width , rect_height ) ; logger . trace ( "paper width {} height {}" , width , height ) ; } final Dimension2D newPaperDimensions = new Dimension2D ( width , height ) ; result = Optional . of ( newPaperDimensions ) ; break ; } if ( result . isPresent ( ) ) { logger . trace ( "Removing paper pattern from patternList (index {})" , index ) ; patternList . remove ( index ) ; } return result ; }
perspective pattern discovery works similar to arena calibration but does not try to identify the outline of the projection area we are only concerned with size , not alignment or angle
