Class DetectPolygonFromContour<T extends ImageGray<T>>
- All Implemented Interfaces:
VerbosePrint
Detects convex polygons with the specified number of sides in an image. Shapes are assumed to be black shapes
against a white background, allowing for thresholding to be used. Subpixel refinement is done using the
provided implementation of RefinePolygonToGray
.
- First the input a gray scale image and a binarized version of it.
- The contours of black blobs are found.
- From the contours polygons are fitted and refined to pixel accuracy.
- (Optional) Sub-pixel refinement of the polygon's edges and/or corners.
The returned polygons will encompass the entire black polygon. Here is a simple example in 1D. If all pixels are white, but pixels ranging from 5 to 10, inclusive, then the returned boundaries would be 5.0 to 11.0. This means that coordinates 5.0 ≤ x < 11.0 are all black. 11.0 is included, but note that the entire pixel 11 is white.
Notes:
- If a lens distortion model is provided for lens distortion, the returned polygon will be in undistorted.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprotected Point2D_F32
protected @Nullable PixelTransform<Point2D_F32>
transforms which can be used to handle lens distortionprotected @Nullable PixelTransform<Point2D_F32>
transforms which can be used to handle lens distortion -
Constructor Summary
ModifierConstructorDescriptionprotected
For unit testingDetectPolygonFromContour
(PointsToPolyline contourToPolyline, boolean outputClockwiseUpY, boolean touchBorder, double contourEdgeThreshold, double tangentEdgeIntensity, BinaryContourFinder contourFinder, Class<T> inputType) Configures the detector. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Discard previously set lens distortion modelsstatic void
flip
(int[] a, int N) Returns the undistorted contour for a shape.int
double
double
int
boolean
isConvex()
void
Examines the undistorted gray scale input image for squares.void
void
setConvex
(boolean convex) void
setLensDistortion
(int width, int height, @Nullable PixelTransform<Point2D_F32> distToUndist, @Nullable PixelTransform<Point2D_F32> undistToDist) Specifies transforms which can be used to change coordinates from distorted to undistorted and the opposite coordinates.void
setNumberOfSides
(int min, int max) void
setVerbose
(@Nullable PrintStream out, @Nullable Set<String> options) protected final boolean
touchesBorder
(List<Point2D_I32> contour) Checks to see if some part of the contour touches the image border.
-
Field Details
-
distToUndist
transforms which can be used to handle lens distortion -
undistToDist
transforms which can be used to handle lens distortion -
distortedPoint
-
-
Constructor Details
-
DetectPolygonFromContour
public DetectPolygonFromContour(PointsToPolyline contourToPolyline, boolean outputClockwiseUpY, boolean touchBorder, double contourEdgeThreshold, double tangentEdgeIntensity, BinaryContourFinder contourFinder, Class<T> inputType) Configures the detector.- Parameters:
contourToPolyline
- Fits a crude polygon to the shape's binary contouroutputClockwiseUpY
- If true then the order of the output polygons will be in clockwise ordertouchBorder
- if true then shapes which touch the image border are allowedcontourEdgeThreshold
- Polygons with an edge intensity less than this are discarded.inputType
- Type of input image it's processing
-
DetectPolygonFromContour
protected DetectPolygonFromContour()For unit testing
-
-
Method Details
-
setLensDistortion
public void setLensDistortion(int width, int height, @Nullable @Nullable PixelTransform<Point2D_F32> distToUndist, @Nullable @Nullable PixelTransform<Point2D_F32> undistToDist) Specifies transforms which can be used to change coordinates from distorted to undistorted and the opposite coordinates. The undistorted image is never explicitly created.
- Parameters:
width
- Input image width. Used in sanity check only.height
- Input image height. Used in sanity check only.distToUndist
- Transform from distorted to undistorted image.undistToDist
- Transform from undistorted to distorted image.
-
resetRuntimeProfiling
public void resetRuntimeProfiling() -
clearLensDistortion
public void clearLensDistortion()Discard previously set lens distortion models -
process
Examines the undistorted gray scale input image for squares. If p- Parameters:
gray
- Input image
-
flip
public static void flip(int[] a, int N) -
getContour
Returns the undistorted contour for a shape. Data is potentially recycled the next time any function in this class is invoked.- Parameters:
info
- Which shape- Returns:
- List of points in the contour
-
touchesBorder
Checks to see if some part of the contour touches the image border. Most likely cropped -
setVerbose
public void setVerbose(@Nullable @Nullable PrintStream out, @Nullable @Nullable Set<String> options) - Specified by:
setVerbose
in interfaceVerbosePrint
-
isConvex
public boolean isConvex() -
setConvex
public void setConvex(boolean convex) -
getAllContours
-
setNumberOfSides
public void setNumberOfSides(int min, int max) -
getMinimumSides
public int getMinimumSides() -
getMaximumSides
public int getMaximumSides() -
getMilliContour
public double getMilliContour() -
getMilliShapes
public double getMilliShapes()
-