@ Override public boolean filterPixelPolygon ( Polygon2D_F64 undistorted , Polygon2D_F64 distorted , GrowQueue_B touches , boolean touchesBorder ) { if ( touchesBorder ) { if ( distorted . size ( ) < 3 ) return false ; int totalRegular = distorted . size ( ) ; for ( int i = 0 ; i < distorted . size ( ) ; i ++ ) { if ( touches . get ( i ) ) totalRegular -- ; } return totalRegular > 0 ; // Would be 3 if it was filled in, but local binary can cause external contour to be concave } else { return distorted . size ( ) == 4 ; } }
If not touching the border then the number of corners must be 4 . If touching the border there must be at least 3 corners not touching the border . 7 corners at most . If there were 8 then all sides of a square would be touching the border . No more than 3 corners since that s the most number of non - border corners a square can have .