Class RefinePolyLineCorner

java.lang.Object
boofcv.alg.shapes.polyline.RefinePolyLineCorner

public class RefinePolyLineCorner extends Object

Optimizing corner placements to a pixel level when given a contour and integer list of approximate corner locations which define set of line segments. Corners are optimized by searching for another near by pixel in the provided contour which reduces the distance of the contour from the line segments. This is intended to optimize the output from SplitMergeLineFit. Can be configured to handle case where line segments form a loop or have disconnected end points.

Each corner is individually optimized once per iteration. The process is repeated until the maximum number of iterations has been reached or there is no change in corner placements.

  • Field Details

    • searchRadius

      protected int searchRadius
  • Constructor Details

    • RefinePolyLineCorner

      public RefinePolyLineCorner(boolean looping, int maxIterations)
      Constructor with configurable parameters
      Parameters:
      looping - true if it loops or false if not
      maxIterations - Number of internal EM iterations
    • RefinePolyLineCorner

      public RefinePolyLineCorner(boolean looping)
      Constructor using default parameters
  • Method Details

    • fit

      public boolean fit(List<Point2D_I32> contour, DogArray_I32 corners)
      Fits a polygon to the contour given an initial set of candidate corners. If not looping the corners must include the end points still. Minimum of 3 points required. Otherwise there's no corner!.
      Parameters:
      contour - Contours around the shape
      corners - (Input) initial set of corners. (output) refined set of corners
    • optimize

      protected int optimize(List<Point2D_I32> contour, int c0, int c1, int c2)
      Searches around the current c1 point for the best place to put the corner
      Returns:
      location of best corner in local search region
    • computeCost

      protected double computeCost(List<Point2D_I32> contour, int c0, int c1, int c2, int offset)
      Computes the distance between the two lines defined by corner points in the contour
      Parameters:
      contour - list of contour points
      c0 - end point of line 0
      c1 - start of line 0 and 1
      c2 - end point of line 1
      offset - added to c1 to make start of lines
      Returns:
      sum of distance of points along contour
    • distanceSum

      protected double distanceSum(LineGeneral2D_F64 line, int c0, int c1, List<Point2D_I32> contour)
      Sum of Euclidean distance of contour points along the line
    • distance

      protected static double distance(LineGeneral2D_F64 line, Point2D_I32 p)
      If A*A + B*B == 1 then a simplified distance formula can be used