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

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

本文整理了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

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

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

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

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

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;
}

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

public Mat dilate(Mat input, int elementSize, int elementShape) {
  Mat outputImage = new Mat();
  Mat element = getKernelFromShape(elementSize, elementShape);
  Imgproc.dilate(input,outputImage, element);
  return outputImage;
}

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

public Mat dilate(Mat input, int elementSize, int elementShape) {
  Mat outputImage = new Mat();
  Mat element = getKernelFromShape(elementSize, elementShape);
  Imgproc.dilate(input,outputImage, element);
  return outputImage;
}

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

public Mat dilate(Mat input, int elementSize, int elementShape) {
  Mat outputImage = new Mat();
  Mat element = getKernelFromShape(elementSize, elementShape);
  Imgproc.dilate(input,outputImage, element);
  return outputImage;
}

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

public Mat dilate(Mat input, int elementSize, int elementShape) {
  Mat outputImage = new Mat();
  Mat element = getKernelFromShape(elementSize, elementShape);
  Imgproc.dilate(input,outputImage, element);
  return outputImage;
}

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

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

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

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

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

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

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

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

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

protected void execute() {
    out = gray();
    Imgproc.equalizeHist(out, out);
    synchronized (mog) {
      mog.apply(out, this.mask, (double) (-10 + learning_rate) / 10);
    }
    Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_DILATE,
        new Size(3, 3));
    Imgproc.dilate(mask, mask, kernel);
    ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>();
    Imgproc.findContours(this.mask, contours, new Mat(),
        Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
    double maxheight = object_max_size * this.in.height() / 100;
    double minheight = object_min_size * this.in.height() / 100;
    Iterator<MatOfPoint> each = contours.iterator();
    each = contours.iterator();
    while (each.hasNext()) {
      MatOfPoint contour = each.next();
      Rect rect = Imgproc.boundingRect(contour);
      if (rect.height > minheight && rect.height < maxheight) {
        Imgproc.rectangle(out, rect.tl(), rect.br(), new Scalar(255,
            0, 0), 1);
      }
    }
  }
}

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

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

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

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

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

public boolean hasChanges(Mat current) {
 int PIXEL_DIFF_THRESHOLD = 5;
 int IMAGE_DIFF_THRESHOLD = 5;
 Mat bg = new Mat();
 Mat cg = new Mat();
 Mat diff = new Mat();
 Mat tdiff = new Mat();
 Imgproc.cvtColor(base, bg, Imgproc.COLOR_BGR2GRAY);
 Imgproc.cvtColor(current, cg, Imgproc.COLOR_BGR2GRAY);
 Core.absdiff(bg, cg, diff);
 Imgproc.threshold(diff, tdiff, PIXEL_DIFF_THRESHOLD, 0.0, Imgproc.THRESH_TOZERO);
 if (Core.countNonZero(tdiff) <= IMAGE_DIFF_THRESHOLD) {
  return false;
 }
 Imgproc.threshold(diff, diff, PIXEL_DIFF_THRESHOLD, 255, Imgproc.THRESH_BINARY);
 Imgproc.dilate(diff, diff, new Mat());
 Mat se = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(5,5));
 Imgproc.morphologyEx(diff, diff, Imgproc.MORPH_CLOSE, se);
 List<MatOfPoint> points = new ArrayList<MatOfPoint>();
 Mat contours = new Mat();
 Imgproc.findContours(diff, points, contours, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
 int n = 0;
 for (Mat pm: points) {
  log(lvl, "(%d) %s", n++, pm);
  printMatI(pm);
 }
 log(lvl, "contours: %s", contours);
 printMatI(contours);
 return true;
}

相关文章

Imgproc类方法