public class PolylineSplitMerge
extends java.lang.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.| Modifier and Type | Class and Description |
|---|---|
static class |
PolylineSplitMerge.CandidatePolyline |
static class |
PolylineSplitMerge.Corner
Corner in the polyline.
|
| Constructor and Description |
|---|
PolylineSplitMerge() |
| Modifier and Type | Method and Description |
|---|---|
static void |
assignLine(java.util.List<georegression.struct.point.Point2D_I32> contour,
int indexA,
int indexB,
georegression.struct.line.LineParametric2D_F64 line)
Assigns the line so that it passes through points A and B.
|
static void |
assignLine(java.util.List<georegression.struct.point.Point2D_I32> contour,
int indexA,
int indexB,
georegression.struct.line.LineSegment2D_F64 line) |
PolylineSplitMerge.CandidatePolyline |
getBestPolyline()
Returns the polyline with the best score or null if it failed to fit a polyline
|
double |
getConvexTest() |
double |
getCornerScorePenalty() |
boofcv.struct.ConfigLength |
getExtraConsider() |
int |
getMaxNumberOfSideSamples() |
boofcv.struct.ConfigLength |
getMaxSideError() |
int |
getMaxSides() |
int |
getMinimumSideLength() |
int |
getMinSides() |
org.ddogleg.struct.FastQueue<PolylineSplitMerge.CandidatePolyline> |
getPolylines() |
double |
getThresholdSideSplitScore() |
boolean |
isConvex() |
boolean |
isLoops() |
boolean |
process(java.util.List<georegression.struct.point.Point2D_I32> contour)
Process the contour and returns true if a polyline could be found.
|
void |
setConvex(boolean convex) |
void |
setConvexTest(double convexTest) |
void |
setCornerScorePenalty(double cornerScorePenalty) |
void |
setExtraConsider(boofcv.struct.ConfigLength extraConsider) |
void |
setLoops(boolean loops) |
void |
setMaxNumberOfSideSamples(int maxNumberOfSideSamples) |
void |
setMaxSideError(boofcv.struct.ConfigLength maxSideError) |
void |
setMaxSides(int maxSides) |
void |
setMinimumSideLength(int minimumSideLength) |
void |
setMinSides(int minSides) |
void |
setSplitter(SplitSelector splitter) |
void |
setThresholdSideSplitScore(double thresholdSideSplitScore) |
public boolean process(java.util.List<georegression.struct.point.Point2D_I32> contour)
contour - Contour. Must be a ordered in CW or CCWpublic static void assignLine(java.util.List<georegression.struct.point.Point2D_I32> contour,
int indexA,
int indexB,
georegression.struct.line.LineParametric2D_F64 line)
public static void assignLine(java.util.List<georegression.struct.point.Point2D_I32> contour,
int indexA,
int indexB,
georegression.struct.line.LineSegment2D_F64 line)
public org.ddogleg.struct.FastQueue<PolylineSplitMerge.CandidatePolyline> getPolylines()
public PolylineSplitMerge.CandidatePolyline getBestPolyline()
public void setLoops(boolean loops)
public boolean isLoops()
public boolean isConvex()
public void setConvex(boolean convex)
public int getMaxSides()
public void setMaxSides(int maxSides)
public int getMinimumSideLength()
public void setMinimumSideLength(int minimumSideLength)
public double getCornerScorePenalty()
public void setCornerScorePenalty(double cornerScorePenalty)
public double getThresholdSideSplitScore()
public void setThresholdSideSplitScore(double thresholdSideSplitScore)
public int getMaxNumberOfSideSamples()
public void setMaxNumberOfSideSamples(int maxNumberOfSideSamples)
public void setSplitter(SplitSelector splitter)
public int getMinSides()
public void setMinSides(int minSides)
public boofcv.struct.ConfigLength getExtraConsider()
public void setExtraConsider(boofcv.struct.ConfigLength extraConsider)
public double getConvexTest()
public void setConvexTest(double convexTest)
public boofcv.struct.ConfigLength getMaxSideError()
public void setMaxSideError(boofcv.struct.ConfigLength maxSideError)