public static Mat drawContours(List<MatOfPoint> contours, Mat mBase) { Mat mResult = Element.getNewMat(); Core.subtract(mBase, mBase, mResult); Imgproc.drawContours(mResult, contours, -1, new Scalar(255)); return mResult; }
public static Mat drawContoursInImage(List<MatOfPoint> contours, Mat mBase) { Mat mResult = Element.getNewMat(); Mat mWork = new Mat(); Imgproc.cvtColor(mBase, mWork, toGray); Imgproc.cvtColor(mWork, mResult, toColor); Imgproc.drawContours(mResult, contours, -1, new Scalar(0, 0, 255)); return mResult; }
public static List<Element> detectChanges(Mat base, Mat mChanged) { int PIXEL_DIFF_THRESHOLD = 3; int IMAGE_DIFF_THRESHOLD = 5; Mat mBaseGray = Element.getNewMat(); Mat mChangedGray = Element.getNewMat(); Mat mDiffAbs = Element.getNewMat(); Mat mDiffTresh = Element.getNewMat(); Mat mChanges = Element.getNewMat(); List<Element> rectangles = new ArrayList<>(); Imgproc.cvtColor(base, mBaseGray, toGray); Imgproc.cvtColor(mChanged, mChangedGray, toGray); Core.absdiff(mBaseGray, mChangedGray, mDiffAbs); Imgproc.threshold(mDiffAbs, mDiffTresh, PIXEL_DIFF_THRESHOLD, 0.0, Imgproc.THRESH_TOZERO); if (Core.countNonZero(mDiffTresh) > IMAGE_DIFF_THRESHOLD) { Imgproc.threshold(mDiffAbs, mDiffAbs, PIXEL_DIFF_THRESHOLD, 255, Imgproc.THRESH_BINARY); Imgproc.dilate(mDiffAbs, mDiffAbs, Element.getNewMat()); Mat se = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(5, 5)); Imgproc.morphologyEx(mDiffAbs, mDiffAbs, Imgproc.MORPH_CLOSE, se); List<MatOfPoint> contours = new ArrayList<MatOfPoint>(); Mat mHierarchy = Element.getNewMat(); Imgproc.findContours(mDiffAbs, contours, mHierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE); rectangles = contoursToRectangle(contours); Core.subtract(mDiffAbs, mDiffAbs, mChanges); Imgproc.drawContours(mChanges, contours, -1, new Scalar(255)); //logShow(mDiffAbs); } return rectangles; }
public FluentCv drawContours(List<MatOfPoint> contours, Color color, int thickness, String... tag) { if (color == null) { for (int i = 0; i < contours.size(); i++) { Imgproc.drawContours(mat, contours, i, colorToScalar(indexedColor(i)), thickness); } } else { Imgproc.drawContours(mat, contours, -1, colorToScalar(color), thickness); } return store(mat, tag); }
@Override public Result process(CvPipeline pipeline) throws Exception { if (contoursStageName == null) { throw new Exception("contoursStageName is required."); } Result result = pipeline.getResult(contoursStageName); if (result == null || result.model == null) { throw new Exception("No model found in results."); } Mat mat = pipeline.getWorkingImage(); List<MatOfPoint> contours = (List<MatOfPoint>) result.model; if (index < 0) { for (int i = 0; i < contours.size(); i++) { Imgproc.drawContours(mat, contours, i, FluentCv.colorToScalar(color == null ? FluentCv.indexedColor(i) : color), thickness); } } else { Imgproc.drawContours(mat, contours, index, FluentCv.colorToScalar(color == null ? FluentCv.indexedColor(index) : color), thickness); } return null; } }
Imgproc.drawContours(image, contours, i, new Scalar(0,255,0), thickness); System.out.println("Area: "+currentArea); Imgproc.drawContours(image, contours, i, new Scalar(0,0,255), thickness);
private void drawConvexHull(MatOfPoint currentContour) { MatOfInt hull = new MatOfInt(); Imgproc.convexHull(currentContour, hull); List<MatOfPoint> hullContours = new ArrayList<MatOfPoint>(); MatOfPoint hullMat = new MatOfPoint(); hullMat.create((int)hull.size().height,1,CvType.CV_32SC2); for(int j = 0; j < hull.size().height ; j++) { int index = (int)hull.get(j, 0)[0]; double[] point = new double[] { currentContour.get(index, 0)[0], currentContour.get(index, 0)[1] }; hullMat.put(j, 0, point); } hullContours.add(hullMat); Imgproc.drawContours(image, hullContours, 0, new Scalar(128,0,0), 2); }
Imgproc.drawContours(mask, multi, i, new Scalar(255, 255, 255), -1);