Example usage for org.opencv.utils Converters Mat_to_vector_Point2d

List of usage examples for org.opencv.utils Converters Mat_to_vector_Point2d

Introduction

In this page you can find the example usage for org.opencv.utils Converters Mat_to_vector_Point2d.

Prototype

public static void Mat_to_vector_Point2d(Mat m, List<Point> pts) 

Source Link

Usage

From source file:opencv_ext.TGG_OpenCV_Util.java

public static Point[][] getExternalConvexHullPoints(BufferedImage bufferedImage) {
    // Initialize
    Mat hierarchy = new Mat();
    Mat image = TGG_OpenCV_Util.bufferedImage2Mat(bufferedImage);
    Point[][] pointResults;//w w  w . j a v a 2s  .c  o m
    // Get Contours
    MatOfInt points = new MatOfInt();
    ArrayList<MatOfPoint> contours = new ArrayList<>();
    Imgproc.findContours(image, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
    // Initialize rows of point results
    pointResults = new Point[contours.size()][0];
    // Iterate over contours
    for (int contour = 0; contour < contours.size(); contour++) {
        // Get convex hull from contour
        Imgproc.convexHull(contours.get(contour), points, true);
        // Convert convex hull to mat of points
        MatOfPoint mopOut = hull2Points(points, contours.get(contour));
        // Convert mat of points to list of points
        ArrayList<Point> pointList = new ArrayList<>();
        Converters.Mat_to_vector_Point2d(mopOut, pointList);
        // Set column size for contour
        pointResults[contour] = new Point[pointList.size()];
        // Fill result array with points
        for (int p = 0; p < pointList.size(); p++) {
            pointResults[contour][p] = pointList.get(p);
        }
    }
    // Return result
    return pointResults;
}