Package boofcv.alg.shapes.polyline
Class RefinePolyLineCorner
java.lang.Object
boofcv.alg.shapes.polyline.RefinePolyLineCorner
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 Summary
-
Constructor Summary
ConstructorDescriptionRefinePolyLineCorner
(boolean looping) Constructor using default parametersRefinePolyLineCorner
(boolean looping, int maxIterations) Constructor with configurable parameters -
Method Summary
Modifier and TypeMethodDescriptionprotected 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 contourprotected static double
distance
(LineGeneral2D_F64 line, Point2D_I32 p) If A*A + B*B == 1 then a simplified distance formula can be usedprotected double
distanceSum
(LineGeneral2D_F64 line, int c0, int c1, List<Point2D_I32> contour) Sum of Euclidean distance of contour points along the lineboolean
fit
(List<Point2D_I32> contour, DogArray_I32 corners) Fits a polygon to the contour given an initial set of candidate corners.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
-
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 notmaxIterations
- Number of internal EM iterations
-
RefinePolyLineCorner
public RefinePolyLineCorner(boolean looping) Constructor using default parameters
-
-
Method Details
-
fit
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 shapecorners
- (Input) initial set of corners. (output) refined set of corners
-
optimize
Searches around the current c1 point for the best place to put the corner- Returns:
- location of best corner in local search region
-
computeCost
Computes the distance between the two lines defined by corner points in the contour- Parameters:
contour
- list of contour pointsc0
- end point of line 0c1
- start of line 0 and 1c2
- end point of line 1offset
- added to c1 to make start of lines- Returns:
- sum of distance of points along contour
-
distanceSum
Sum of Euclidean distance of contour points along the line -
distance
If A*A + B*B == 1 then a simplified distance formula can be used
-