Class RefinePolygonToGrayLine<T extends ImageGray<T>>

java.lang.Object
boofcv.alg.shapes.polygon.RefinePolygonToGrayLine<T>
All Implemented Interfaces:
RefinePolygonToGray<T>

public class RefinePolygonToGrayLine<T extends ImageGray<T>> extends Object implements RefinePolygonToGray<T>

Improves the fits of a polygon's which is darker or lighter than the background. Info's edges are assumed to be perfectly straight lines. The edges are processed individually and fit to a line using weighted regression. Both black squares with white backgrounds and white shapes with black backgrounds can be found. The edges are selected to maximize the difference between light and dark regions.

For example, assume an image axis aligned rectangle has a lower extent of 1,2 and a upper extent of 12,15, is entirely filled, excluding the upper extent pixels (as is typical). Then the found lower and upper extends of the found polygon will also be 1,2 and 12,15.

If a line lies entirely along the image border it is not modified. If part of it lies along the image then only points not near the border are used to optimize its location.

For input polygons which are in undistorted coordinates by with a distorted image call getSnapToEdge() and invoke BaseIntegralEdge.setTransform(PixelTransform<Point2D_F32>).

  • Field Details

  • Constructor Details

    • RefinePolygonToGrayLine

      public RefinePolygonToGrayLine(double cornerOffset, int lineSamples, int sampleRadius, int maxIterations, double convergeTolPixels, double maxCornerChangePixel, Class<T> imageType)
      Constructor which provides full access to all parameters. See code documents value a description of these variables.
    • RefinePolygonToGrayLine

      public RefinePolygonToGrayLine(int numSides, Class<T> imageType)
      Simplified constructor which uses reasonable default values for most variables
      Parameters:
      numSides - Number of sides on the polygon
      imageType - Type of input image it processes
  • Method Details

    • setImage

      public void setImage(T image)
      Sets the image which is going to be processed. If a transform is to be used BaseIntegralEdge.setTransform(boofcv.struct.distort.PixelTransform<georegression.struct.point.Point2D_F32>) should be called before this.
      Specified by:
      setImage in interface RefinePolygonToGray<T extends ImageGray<T>>
    • setLensDistortion

      public void setLensDistortion(int width, int height, @Nullable @Nullable PixelTransform<Point2D_F32> distToUndist, @Nullable @Nullable PixelTransform<Point2D_F32> undistToDist)
      Description copied from interface: RefinePolygonToGray
      Specifies lens distortion
      Specified by:
      setLensDistortion in interface RefinePolygonToGray<T extends ImageGray<T>>
    • clearLensDistortion

      public void clearLensDistortion()
      Description copied from interface: RefinePolygonToGray
      Clears the previously set lens distortion
      Specified by:
      clearLensDistortion in interface RefinePolygonToGray<T extends ImageGray<T>>
    • refine

      public boolean refine(Polygon2D_F64 input, Polygon2D_F64 output)
      Refines the fit a polygon by snapping it to the edges.
      Specified by:
      refine in interface RefinePolygonToGray<T extends ImageGray<T>>
      Parameters:
      input - (input) Initial estimate for the polygon. CW or CCW ordering doesn't matter.
      output - (output) the fitted polygon
      Returns:
      true if successful or false if it failed
    • optimize

      protected boolean optimize(Polygon2D_F64 seed, Polygon2D_F64 current)
      Refines the initial line estimates using EM. The number of iterations is fixed.
    • optimize

      protected boolean optimize(Point2D_F64 a, Point2D_F64 b, LineGeneral2D_F64 found)
      Fits a line defined by the two points. When fitting the line the weight of the edge is used to determine how influential the point is
      Parameters:
      a - Corner point in image coordinates.
      b - Corner point in image coordinates.
      found - (output) Line in image coordinates
      Returns:
      true if successful or false if it failed
    • setTransform

      public void setTransform(PixelTransform<Point2D_F32> undistToDist)
      Used to specify a transform that is applied to pixel coordinates to bring them back into original input image coordinates. For example if the input image has lens distortion but the edge were found in undistorted coordinates this code needs to know how to go from undistorted back into distorted image coordinates in order to read the pixel's value.
      Parameters:
      undistToDist - Pixel transformation from undistorted pixels into the actual distorted input image..
    • getSnapToEdge

      public SnapToLineEdge<T> getSnapToEdge()