Class ShapeFittingOps

java.lang.Object
boofcv.alg.shapes.ShapeFittingOps

public class ShapeFittingOps
extends Object
Functions for fitting shapes to sequences of points. Points sequences are often found by computing a shape's contour or edge.
See Also:
CannyEdge, BinaryImageOps.contour(GrayU8, boofcv.struct.ConnectRule, GrayS32)
  • Constructor Details

    • ShapeFittingOps

      public ShapeFittingOps()
  • Method Details

    • fitPolygon

      public static List<PointIndex_I32> fitPolygon​(List<Point2D_I32> sequence, boolean loop, int minimumSideLength, double cornerPenalty)

      Fits a polygon to the provided sequence of connected points. The found polygon is returned as a list of vertices. Each point in the original sequence is guaranteed to be within "toleranceDist' of a line segment.

      Internally a split-and-merge algorithm is used. See referenced classes for more information. Consider using internal algorithms directly if this function is a performance bottleneck.

      Parameters:
      sequence - Ordered and connected list of points.
      loop - If true the sequence is a connected at both ends, otherwise it is assumed to not be.
      minimumSideLength - The minimum allowed side length in pixels. Try 10
      cornerPenalty - How much a corner is penalized. Try 0.25
      Returns:
      Vertexes in the fit polygon.
      See Also:
      PolylineSplitMerge
    • fitEllipse_F64

      public static FitData<EllipseRotated_F64> fitEllipse_F64​(List<Point2D_F64> points, int iterations, boolean computeError, @Nullable @Nullable FitData<EllipseRotated_F64> outputStorage)
      Computes the best fit ellipse based on minimizing Euclidean distance. An estimate is initially provided using algebraic algorithm which is then refined using non-linear optimization. The amount of non-linear optimization can be controlled using 'iterations' parameter. Will work with partial and complete contours of objects.

      NOTE: To improve speed, make calls directly to classes in Georegression. Look at the code for details.

      Parameters:
      points - (Input) Set of unordered points. Not modified.
      iterations - Number of iterations used to refine the fit. If set to zero then an algebraic solution is returned.
      computeError - If true it will compute the average Euclidean distance error
      outputStorage - (Output/Optional) Storage for the ellipse. Can be null.
      Returns:
      Found ellipse.
    • fitEllipse_I32

      public static FitData<EllipseRotated_F64> fitEllipse_I32​(List<Point2D_I32> points, int iterations, boolean computeError, @Nullable @Nullable FitData<EllipseRotated_F64> outputStorage)
      Convenience function. Same as fitEllipse_F64(java.util.List, int, boolean, FitData), but converts the set of integer points into floating point points.
      Parameters:
      points - (Input) Set of unordered points. Not modified.
      iterations - Number of iterations used to refine the fit. If set to zero then an algebraic solution is returned.
      computeError - If true it will compute the average Euclidean distance error
      outputStorage - (Output/Optional) Storage for the ellipse. Can be null
      Returns:
      Found ellipse.
    • convert_I32_F64

      public static List<Point2D_F64> convert_I32_F64​(List<Point2D_I32> points)
      Converts a list of I32 points into F64
      Parameters:
      points - Original points
      Returns:
      Converted points
    • convert_I32_F64

      public static DogArray<Point2D_F64> convert_I32_F64​(List<Point2D_I32> input, @Nullable @Nullable DogArray<Point2D_F64> output)
    • convert_I32_F32

      public static List<Point2D_F32> convert_I32_F32​(List<Point2D_I32> points)
    • convert_I32_F32

      public static DogArray<Point2D_F32> convert_I32_F32​(List<Point2D_I32> input, @Nullable @Nullable DogArray<Point2D_F32> output)
    • averageCircle_I32

      public static FitData<Circle2D_F64> averageCircle_I32​(List<Point2D_I32> points, DogArray_F64 optional, @Nullable @Nullable FitData<Circle2D_F64> outputStorage)
      Computes a circle which has it's center at the mean position of the provided points and radius is equal to the average distance of each point from the center. While fast to compute the provided circle is not a best fit circle by any reasonable metric, except for special cases.
      Parameters:
      points - (Input) Set of unordered points. Not modified.
      optional - (Optional) Used internally to store the distance of each point from the center. Can be null.
      outputStorage - (Output/Optional) Storage for results. If null then a new circle instance will be returned.
      Returns:
      The found circle fit.
    • averageCircle_F64

      public static FitData<Circle2D_F64> averageCircle_F64​(List<Point2D_F64> points, @Nullable @Nullable DogArray_F64 optional, @Nullable @Nullable FitData<Circle2D_F64> outputStorage)
      Computes a circle which has it's center at the mean position of the provided points and radius is equal to the average distance of each point from the center. While fast to compute the provided circle is not a best fit circle by any reasonable metric, except for special cases.
      Parameters:
      points - (Input) Set of unordered points. Not modified.
      optional - (Optional) Used internally to store the distance of each point from the center. Can be null.
      outputStorage - (Output/Optional) Storage for results. If null then a new circle instance will be returned.
      Returns:
      The found circle fit.
    • indexToPointIndex

      public static void indexToPointIndex​(List<Point2D_I32> sequence, DogArray_I32 indexes, DogArray<PointIndex_I32> output)
      Converts the list of indexes in a sequence into a list of PointIndex_I32.
      Parameters:
      sequence - Sequence of points.
      indexes - List of indexes in the sequence.
      output - Output list of PointIndex_I32.