Class PolylineSplitMerge

java.lang.Object
boofcv.alg.shapes.polyline.splitmerge.PolylineSplitMerge

public class PolylineSplitMerge extends Object

Fits a polyline to a contour by fitting the simplest model (3 sides) and adding more sides to it. The number of sides is increased until the number of sides reaches maxSides + extraConsider or it already has fit the contour to within the specified precision. It then merges lines together until no more can be merged.

When a side is added to the polygon it selects the side in which the score will be improved the most by splitting. The score is computed by computing the euclidean distance a point on the contour is from the line segment it belongs to. Note that distance from a line segment and not a line is found, thus if the closest point is past an end point the end point is used. The final score is the average distance.

A set of polylines is found and scored. The best polyline is the one with the best overall score. The overall score is found by summing up the average error across all line segments (sum of segment scores dividing by the number of segments) [1] and adding a fixed penalty for each line segment. Without a penalty the polyline with the largest number of sides will almost always be selected.

For a complete description of all parameters see the source code.

[1] Note that the score is NOT weighted based on the number of points in a line segment. This was done at one point at produced much worse results.

The polyline will always be in counter-clockwise ordering.
  • Constructor Details

    • PolylineSplitMerge

      public PolylineSplitMerge()
  • Method Details

    • process

      public boolean process(List<Point2D_I32> contour)
      Process the contour and returns true if a polyline could be found.
      Parameters:
      contour - Contour. Must be a ordered in CW or CCW
      Returns:
      true for success or false if one could not be fit
    • assignLine

      public static void assignLine(List<Point2D_I32> contour, int indexA, int indexB, LineParametric2D_F64 line)
      Assigns the line so that it passes through points A and B.
    • assignLine

      public static void assignLine(List<Point2D_I32> contour, int indexA, int indexB, LineSegment2D_F64 line)
    • getPolylines

    • getBestPolyline

      @Nullable public @Nullable PolylineSplitMerge.CandidatePolyline getBestPolyline()
      Returns the polyline with the best score or null if it failed to fit a polyline
    • setMinimumSideLength

      public void setMinimumSideLength(int minimumSideLength)
    • setExtraConsider

      public void setExtraConsider(ConfigLength extra)
    • setMaxSideError

      public void setMaxSideError(ConfigLength config)