Class DetectPolygonFromContour<T extends ImageGray<T>>


  • public class DetectPolygonFromContour<T extends ImageGray<T>>
    extends java.lang.Object
    TODO Update documentation

    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.

    Processing Steps:
    1. First the input a gray scale image and a binarized version of it.
    2. The contours of black blobs are found.
    3. From the contours polygons are fitted and refined to pixel accuracy.
    4. (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.
    • Constructor Detail

      • DetectPolygonFromContour

        public DetectPolygonFromContour​(PointsToPolyline contourToPolyline,
                                        ConfigLength minimumContour,
                                        boolean outputClockwise,
                                        boolean touchBorder,
                                        double contourEdgeThreshold,
                                        double tangentEdgeIntensity,
                                        BinaryContourFinder contourFinder,
                                        java.lang.Class<T> inputType)
        Configures the detector.
        Parameters:
        contourToPolyline - Fits a crude polygon to the shape's binary contour
        minimumContour - Minimum allowed length of a contour. Copy stored internally. Try 50 pixels.
        outputClockwise - If true then the order of the output polygons will be in clockwise order
        touchBorder - if true then shapes which touch the image border are allowed
        contourEdgeThreshold - 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 Detail

      • setLensDistortion

        public void setLensDistortion​(int width,
                                      int height,
                                      PixelTransform<Point2D_F32> distToUndist,
                                      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

        public void process​(T gray,
                            GrayU8 binary)
        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

        public java.util.List<Point2D_I32> getContour​(DetectPolygonFromContour.Info info)
        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

        protected final boolean touchesBorder​(java.util.List<Point2D_I32> contour)
        Checks to see if some part of the contour touches the image border. Most likely cropped
      • isConvex

        public boolean isConvex()
      • setConvex

        public void setConvex​(boolean convex)
      • isOutputClockwise

        public boolean isOutputClockwise()
      • getAllContours

        public java.util.List<ContourPacked> getAllContours()
      • getInputType

        public java.lang.Class<T> getInputType()
      • setNumberOfSides

        public void setNumberOfSides​(int min,
                                     int max)
      • getMinimumSides

        public int getMinimumSides()
      • getMaximumSides

        public int getMaximumSides()
      • setOutputClockwise

        public void setOutputClockwise​(boolean outputClockwise)
      • setVerbose

        public void setVerbose​(boolean verbose)
      • getContourEdgeThreshold

        public double getContourEdgeThreshold()
      • setContourEdgeThreshold

        public void setContourEdgeThreshold​(double contourEdgeThreshold)
      • getMilliContour

        public double getMilliContour()
      • getMilliShapes

        public double getMilliShapes()