Class ContoursHelper


  • public class ContoursHelper
    extends Object
    Helper methods around object contours.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    • Constructor Detail

      • ContoursHelper

        public ContoursHelper()
    • Method Detail

      • findContours

        public static org.bytedeco.opencv.opencv_core.MatVector findContours​(BufferedImage img,
                                                                             int threshold,
                                                                             boolean inverse)
        Finds the contours in the image. Automatically converts it to binary.
        Parameters:
        img - the image to find the contours in
        threshold - the threshold for generating the binary image, eg 127
        inverse - whether to generate the inverse binary ie black instead of white
        Returns:
        the list of contours, must be closed by caller
      • findContours

        public static org.bytedeco.opencv.opencv_core.MatVector findContours​(org.bytedeco.opencv.opencv_core.Mat mat,
                                                                             int conversion,
                                                                             int threshold,
                                                                             boolean inverse)
        Finds the contours in the image. Automatically converts it to binary.
        Parameters:
        mat - the image to find the contours in
        conversion - the color conversion to perform, eg COLOR_RGBA2GRAY
        threshold - the threshold for generating the binary image, eg 127
        inverse - whether to generate the inverse binary ie black instead of white
        Returns:
        the list of contours, must be closed by caller
      • contourToCoordinates

        public static com.github.fracpete.javautils.struct.Struct2<int[],​int[]> contourToCoordinates​(org.bytedeco.opencv.opencv_core.Mat contour)
        Turns the contour matrix into x/y int arrays of coordinates.
        Parameters:
        contour - the contour to convert
        Returns:
        the x/y coordinates
      • contoursToPolygons

        public static List<Polygon> contoursToPolygons​(org.bytedeco.opencv.opencv_core.MatVector contours)
        Turns the contours into polygons. Caller must close the contours object.
        Parameters:
        contours - the contours to convert
        Returns:
        the polygons
      • contoursToPolygons

        public static List<Polygon> contoursToPolygons​(org.bytedeco.opencv.opencv_core.MatVector contours,
                                                       int min,
                                                       int max)
        Turns the contours into polygons that fit the min/max restrictions. Caller must close the contours object.
        Parameters:
        contours - the contours to convert
        min - the minimum size (width and height), ignored if <= 0
        max - the maximum size (width and height), ignored if <= 0
        Returns:
        the polygons