Search in sources :

Example 1 with PolylineSplitMerge

use of boofcv.alg.shapes.polyline.splitmerge.PolylineSplitMerge in project BoofCV by lessthanoptimal.

the class ShapeFittingOps method fitPolygon.

/**
 * <p>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.</p>
 *
 * <p>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.</p>
 *
 * @see SplitMergeLineFitLoop
 * @see SplitMergeLineFitSegment
 *
 * @param sequence Ordered and connected list of points.
 * @param loop If true the sequence is a connected at both ends, otherwise it is assumed to not be.
 * @param minimumSideLength The minimum allowed side length in pixels. Try 10
 * @param cornerPenalty How much a corner is penalized. Try 0.25
 * @return Vertexes in the fit polygon.
 */
public static List<PointIndex_I32> fitPolygon(List<Point2D_I32> sequence, boolean loop, int minimumSideLength, double cornerPenalty) {
    PolylineSplitMerge alg = new PolylineSplitMerge();
    alg.setLoops(loop);
    alg.setMinimumSideLength(minimumSideLength);
    alg.setCornerScorePenalty(cornerPenalty);
    alg.process(sequence);
    PolylineSplitMerge.CandidatePolyline best = alg.getBestPolyline();
    FastQueue<PointIndex_I32> output = new FastQueue<>(PointIndex_I32.class, true);
    if (best != null) {
        indexToPointIndex(sequence, best.splits, output);
    }
    return new ArrayList<>(output.toList());
}
Also used : FastQueue(org.ddogleg.struct.FastQueue) PointIndex_I32(boofcv.struct.PointIndex_I32) ArrayList(java.util.ArrayList) PolylineSplitMerge(boofcv.alg.shapes.polyline.splitmerge.PolylineSplitMerge)

Aggregations

PolylineSplitMerge (boofcv.alg.shapes.polyline.splitmerge.PolylineSplitMerge)1 PointIndex_I32 (boofcv.struct.PointIndex_I32)1 ArrayList (java.util.ArrayList)1 FastQueue (org.ddogleg.struct.FastQueue)1