public boolean refine ( DetectPolygonFromContour . Info info ) { double before , after ; if ( edgeIntensity . computeEdge ( info . polygon , ! detector . isOutputClockwise ( ) ) ) { before = edgeIntensity . getAverageOutside ( ) - edgeIntensity . getAverageInside ( ) ; } else { return false ; } boolean success = false ; if ( refineContour != null ) { List < Point2D_I32 > contour = detector . getContour ( info ) ; refineContour . process ( contour , info . splits , work ) ; if ( adjustForBias != null ) adjustForBias . process ( work , detector . isOutputClockwise ( ) ) ; if ( edgeIntensity . computeEdge ( work , ! detector . isOutputClockwise ( ) ) ) { after = edgeIntensity . getAverageOutside ( ) - edgeIntensity . getAverageInside ( ) ; if ( after > before ) { info . edgeInside = edgeIntensity . getAverageInside ( ) ; info . edgeOutside = edgeIntensity . getAverageOutside ( ) ; info . polygon . set ( work ) ; success = true ; before = after ; } } } if ( functionAdjust != null ) { functionAdjust . adjust ( info , detector . isOutputClockwise ( ) ) ; } if ( refineGray != null ) { work . vertexes . resize ( info . polygon . size ( ) ) ; if ( refineGray . refine ( info . polygon , work ) ) { if ( edgeIntensity . computeEdge ( work , ! detector . isOutputClockwise ( ) ) ) { after = edgeIntensity . getAverageOutside ( ) - edgeIntensity . getAverageInside ( ) ; // basically, unless it diverged stick with this optimization // a near tie if ( after * 1.5 > before ) { info . edgeInside = edgeIntensity . getAverageInside ( ) ; info . edgeOutside = edgeIntensity . getAverageOutside ( ) ; info . polygon . set ( work ) ; success = true ; } } } } return success ; }
Refines the fit to the specified polygon . Only info . polygon is modified