Class DetectPolygonFromContour<T extends ImageGray<T>>

java.lang.Object
boofcv.alg.shapes.polygon.DetectPolygonFromContour<T>
All Implemented Interfaces:
VerbosePrint

public class DetectPolygonFromContour<T extends ImageGray<T>> extends Object implements 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.

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.
  • Field Details

    • distToUndist

      @Nullable protected @Nullable PixelTransform<Point2D_F32> distToUndist
      transforms which can be used to handle lens distortion
    • undistToDist

      @Nullable protected @Nullable PixelTransform<Point2D_F32> undistToDist
      transforms which can be used to handle lens distortion
    • distortedPoint

      protected Point2D_F32 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 contour
      outputClockwiseUpY - 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 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

      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 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(List<Point2D_I32> contour)
      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 interface VerbosePrint
    • isConvex

      public boolean isConvex()
    • setConvex

      public void setConvex(boolean convex)
    • getAllContours

      public List<ContourPacked> 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()