List of usage examples for org.opencv.imgproc Imgproc drawContours
public static void drawContours(Mat image, List<MatOfPoint> contours, int contourIdx, Scalar color, int thickness, int lineType, Mat hierarchy, int maxLevel, Point offset)
From source file:qupath.opencv.processing.OpenCVTools.java
License:Open Source License
public static void labelImage(Mat matBinary, Mat matLabels, int contourType) { List<MatOfPoint> contours = new ArrayList<>(); Mat hierarchy = new Mat(); Imgproc.findContours(matBinary, contours, hierarchy, contourType, Imgproc.CHAIN_APPROX_SIMPLE); // It's convoluted, but drawing contours this way is *much* faster than passing the full list (which is copied by the OpenCV 2.4.9 Java code) List<MatOfPoint> temp = new ArrayList<>(1); int i = 2;/*from w w w. java 2 s . c o m*/ int ind = 0; for (MatOfPoint contour : contours) { temp.clear(); temp.add(contour); Imgproc.drawContours(matLabels, temp, 0, new Scalar(i++), -1, 8, hierarchy.col(ind), 2, new Point(0, 0)); // Imgproc.drawContours(matLabels, temp, 0, new Scalar(i++), -1); ind++; } }
From source file:uk.ac.horizon.artcodes.drawer.MarkerThumbnailDrawer.java
License:Open Source License
@Override public Mat drawMarker(Marker marker, ArrayList<MatOfPoint> contours, Mat hierarchy, Rect boundingRect, Mat imageToDrawOn) {/*from ww w . java2s. c om*/ if (imageToDrawOn == null) { if (boundingRect == null) { boundingRect = Imgproc.boundingRect(contours.get(marker.markerIndex)); } Mat output = new Mat(boundingRect.size(), CvType.CV_8UC4, BACKGROUND); Imgproc.drawContours(output, contours, marker.markerIndex, COLOR, Core.FILLED, Core.LINE_8, hierarchy, 2, new Point(-boundingRect.tl().x, -boundingRect.tl().y)); return output; } else { Imgproc.drawContours(imageToDrawOn, contours, marker.markerIndex, COLOR, Core.FILLED, Core.LINE_8, hierarchy, 2, new Point(0, 0)); return imageToDrawOn; } }