Package adams.data.opencv
Class ContoursHelper
- java.lang.Object
-
- adams.data.opencv.ContoursHelper
-
public class ContoursHelper extends Object
Helper methods around object contours.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
-
-
Constructor Summary
Constructors Constructor Description ContoursHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static List<Polygon>
contoursToPolygons(org.bytedeco.opencv.opencv_core.MatVector contours)
Turns the contours into polygons.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.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.static org.bytedeco.opencv.opencv_core.MatVector
findContours(BufferedImage img, int threshold, boolean inverse)
Finds the contours in the image.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.
-
-
-
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 inthreshold
- the threshold for generating the binary image, eg 127inverse
- 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 inconversion
- the color conversion to perform, eg COLOR_RGBA2GRAYthreshold
- the threshold for generating the binary image, eg 127inverse
- 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 convertmin
- the minimum size (width and height), ignored if <= 0max
- the maximum size (width and height), ignored if <= 0- Returns:
- the polygons
-
-