org.opencv.imgproc.Imgproc.dilate()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(338)

本文整理了Java中org.opencv.imgproc.Imgproc.dilate()方法的一些代码示例,展示了Imgproc.dilate()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Imgproc.dilate()方法的具体详情如下:
包路径:org.opencv.imgproc.Imgproc
类名称:Imgproc
方法名:dilate

Imgproc.dilate介绍

[英]Dilates an image by using a specific structuring element.

The function dilates the source image using the specified structuring element that determines the shape of a pixel neighborhood over which the maximum is taken:

dst(x,y) = max _((x',y'): element(x',y') != 0) src(x+x',y+y')

The function supports the in-place mode. Dilation can be applied several (iterations) times. In case of multi-channel images, each channel is processed independently.

Note:

  • An example using the morphological dilate operation can be found at opencv_source_code/samples/cpp/morphology2.cpp
    [中]使用特定的结构元素放大图像。
    该函数使用指定的结构元素对源图像进行放大,该结构元素确定取最大值的像素邻域的形状:
    dst(x,y)=最大值((x',y'):元素(x',y')!=0)src(x+x',y+y')
    该功能支持就地模式。膨胀可以应用多次(iterations)。在多通道图像的情况下,每个通道独立处理。
    注:
    *在opencv_源代码/samples/cpp/morphology2中可以找到使用形态学扩张操作的示例。cpp

代码示例

代码示例来源:origin: RaiMan/SikuliX2

  1. public static List<Element> getElements(Picture picture, boolean external) {
  2. Mat mEdges = detectEdges(picture);
  3. List<MatOfPoint> contours = getContours(mEdges, external);
  4. Mat mResult = drawContours(contours, mEdges);
  5. Imgproc.dilate(mResult, mResult, Element.getNewMat());
  6. Imgproc.dilate(mResult, mResult, Element.getNewMat());
  7. return contoursToRectangle(getContours(mResult, external));
  8. }

代码示例来源:origin: RaiMan/SikuliX2

  1. mShot = shot.getContent().clone();
  2. Imgproc.fillPoly(mShot, contours, oColorBlack);
  3. Imgproc.dilate(mShot, mShot, Element.getNewMat());
  4. contours = Finder.getElement(new Picture(mShot));
  5. resizeToFrame(new Picture(mShot));

代码示例来源:origin: RaiMan/SikuliX2

  1. public static List<Element> detectChanges(Mat base, Mat mChanged) {
  2. int PIXEL_DIFF_THRESHOLD = 3;
  3. int IMAGE_DIFF_THRESHOLD = 5;
  4. Mat mBaseGray = Element.getNewMat();
  5. Mat mChangedGray = Element.getNewMat();
  6. Mat mDiffAbs = Element.getNewMat();
  7. Mat mDiffTresh = Element.getNewMat();
  8. Mat mChanges = Element.getNewMat();
  9. List<Element> rectangles = new ArrayList<>();
  10. Imgproc.cvtColor(base, mBaseGray, toGray);
  11. Imgproc.cvtColor(mChanged, mChangedGray, toGray);
  12. Core.absdiff(mBaseGray, mChangedGray, mDiffAbs);
  13. Imgproc.threshold(mDiffAbs, mDiffTresh, PIXEL_DIFF_THRESHOLD, 0.0, Imgproc.THRESH_TOZERO);
  14. if (Core.countNonZero(mDiffTresh) > IMAGE_DIFF_THRESHOLD) {
  15. Imgproc.threshold(mDiffAbs, mDiffAbs, PIXEL_DIFF_THRESHOLD, 255, Imgproc.THRESH_BINARY);
  16. Imgproc.dilate(mDiffAbs, mDiffAbs, Element.getNewMat());
  17. Mat se = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(5, 5));
  18. Imgproc.morphologyEx(mDiffAbs, mDiffAbs, Imgproc.MORPH_CLOSE, se);
  19. List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
  20. Mat mHierarchy = Element.getNewMat();
  21. Imgproc.findContours(mDiffAbs, contours, mHierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
  22. rectangles = contoursToRectangle(contours);
  23. Core.subtract(mDiffAbs, mDiffAbs, mChanges);
  24. Imgproc.drawContours(mChanges, contours, -1, new Scalar(255));
  25. //logShow(mDiffAbs);
  26. }
  27. return rectangles;
  28. }

代码示例来源:origin: JavaOpenCVBook/code

  1. public Mat dilate(Mat input, int elementSize, int elementShape) {
  2. Mat outputImage = new Mat();
  3. Mat element = getKernelFromShape(elementSize, elementShape);
  4. Imgproc.dilate(input,outputImage, element);
  5. return outputImage;
  6. }

代码示例来源:origin: JavaOpenCVBook/code

  1. public Mat dilate(Mat input, int elementSize, int elementShape) {
  2. Mat outputImage = new Mat();
  3. Mat element = getKernelFromShape(elementSize, elementShape);
  4. Imgproc.dilate(input,outputImage, element);
  5. return outputImage;
  6. }

代码示例来源:origin: JavaOpenCVBook/code

  1. public Mat dilate(Mat input, int elementSize, int elementShape) {
  2. Mat outputImage = new Mat();
  3. Mat element = getKernelFromShape(elementSize, elementShape);
  4. Imgproc.dilate(input,outputImage, element);
  5. return outputImage;
  6. }

代码示例来源:origin: JavaOpenCVBook/code

  1. public Mat dilate(Mat input, int elementSize, int elementShape) {
  2. Mat outputImage = new Mat();
  3. Mat element = getKernelFromShape(elementSize, elementShape);
  4. Imgproc.dilate(input,outputImage, element);
  5. return outputImage;
  6. }

代码示例来源:origin: us.ihmc/ihmc-perception

  1. public static void morphologicallyOpen(Mat hsvImage, int size)
  2. {
  3. Imgproc.erode(hsvImage, hsvImage, Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(size, size)));
  4. Imgproc.dilate(hsvImage, hsvImage, Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(size, size)));
  5. }

代码示例来源:origin: us.ihmc/IHMCPerception

  1. public static void morphologicallyClose(Mat hsvImage, int size)
  2. {
  3. Imgproc.dilate(hsvImage, hsvImage, Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(size, size)));
  4. Imgproc.erode(hsvImage, hsvImage, Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(size, size)));
  5. }

代码示例来源:origin: us.ihmc/IHMCPerception

  1. public static void morphologicallyOpen(Mat hsvImage, int size)
  2. {
  3. Imgproc.erode(hsvImage, hsvImage, Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(size, size)));
  4. Imgproc.dilate(hsvImage, hsvImage, Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(size, size)));
  5. }

代码示例来源:origin: us.ihmc/ihmc-perception

  1. public static void morphologicallyClose(Mat hsvImage, int size)
  2. {
  3. Imgproc.dilate(hsvImage, hsvImage, Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(size, size)));
  4. Imgproc.erode(hsvImage, hsvImage, Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(size, size)));
  5. }

代码示例来源:origin: hschott/Camdroid

  1. protected void execute() {
  2. out = gray();
  3. Imgproc.equalizeHist(out, out);
  4. synchronized (mog) {
  5. mog.apply(out, this.mask, (double) (-10 + learning_rate) / 10);
  6. }
  7. Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_DILATE,
  8. new Size(3, 3));
  9. Imgproc.dilate(mask, mask, kernel);
  10. ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>();
  11. Imgproc.findContours(this.mask, contours, new Mat(),
  12. Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
  13. double maxheight = object_max_size * this.in.height() / 100;
  14. double minheight = object_min_size * this.in.height() / 100;
  15. Iterator<MatOfPoint> each = contours.iterator();
  16. each = contours.iterator();
  17. while (each.hasNext()) {
  18. MatOfPoint contour = each.next();
  19. Rect rect = Imgproc.boundingRect(contour);
  20. if (rect.height > minheight && rect.height < maxheight) {
  21. Imgproc.rectangle(out, rect.tl(), rect.br(), new Scalar(255,
  22. 0, 0), 1);
  23. }
  24. }
  25. }
  26. }

代码示例来源:origin: us.ihmc/IHMCPerception

  1. Imgproc.dilate(mat, mat, Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(20, 20)));
  2. Imgproc.dilate(mat, mat, Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(20, 20)));
  3. Imgproc.erode(mat, mat, Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(20, 20)));

代码示例来源:origin: us.ihmc/ihmc-perception

  1. Imgproc.dilate(mat, mat, Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(20, 20)));
  2. Imgproc.dilate(mat, mat, Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(20, 20)));
  3. Imgproc.erode(mat, mat, Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(20, 20)));

代码示例来源:origin: com.sikulix/sikulixapi

  1. public boolean hasChanges(Mat current) {
  2. int PIXEL_DIFF_THRESHOLD = 5;
  3. int IMAGE_DIFF_THRESHOLD = 5;
  4. Mat bg = new Mat();
  5. Mat cg = new Mat();
  6. Mat diff = new Mat();
  7. Mat tdiff = new Mat();
  8. Imgproc.cvtColor(base, bg, Imgproc.COLOR_BGR2GRAY);
  9. Imgproc.cvtColor(current, cg, Imgproc.COLOR_BGR2GRAY);
  10. Core.absdiff(bg, cg, diff);
  11. Imgproc.threshold(diff, tdiff, PIXEL_DIFF_THRESHOLD, 0.0, Imgproc.THRESH_TOZERO);
  12. if (Core.countNonZero(tdiff) <= IMAGE_DIFF_THRESHOLD) {
  13. return false;
  14. }
  15. Imgproc.threshold(diff, diff, PIXEL_DIFF_THRESHOLD, 255, Imgproc.THRESH_BINARY);
  16. Imgproc.dilate(diff, diff, new Mat());
  17. Mat se = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(5,5));
  18. Imgproc.morphologyEx(diff, diff, Imgproc.MORPH_CLOSE, se);
  19. List<MatOfPoint> points = new ArrayList<MatOfPoint>();
  20. Mat contours = new Mat();
  21. Imgproc.findContours(diff, points, contours, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
  22. int n = 0;
  23. for (Mat pm: points) {
  24. log(lvl, "(%d) %s", n++, pm);
  25. printMatI(pm);
  26. }
  27. log(lvl, "contours: %s", contours);
  28. printMatI(contours);
  29. return true;
  30. }

相关文章

Imgproc类方法