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

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

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

Imgproc.filter2D介绍

[英]Convolves an image with the kernel.

The function applies an arbitrary linear filter to an image. In-place operation is supported. When the aperture is partially outside the image, the function interpolates outlier pixel values according to the specified border mode.

The function does actually compute correlation, not the convolution:

dst(x,y) = sum(by: 0

That is, the kernel is not mirrored around the anchor point. If you need a real convolution, flip the kernel using "flip" and set the new anchor to (kernel.cols - anchor.x - 1, kernel.rows - anchor.y - 1).

The function uses the DFT-based algorithm in case of sufficiently large kernels (~11 x 11 or larger) and the direct algorithm (that uses the engine retrieved by "createLinearFilter") for small kernels.
[中]将映像与内核卷积。
该函数对图像应用任意线性滤波器。支持就地操作。当光圈部分位于图像外部时,该函数将根据指定的边界模式插值异常像素值。
该函数实际上计算相关性,而不是卷积:
dst(x,y)=和(由:0)
也就是说,内核没有围绕锚点进行镜像。如果需要真正的卷积,请使用“flip”翻转内核,并将新的定位点设置为(kernel.cols - anchor.x - 1, kernel.rows - anchor.y - 1)
对于足够大的内核(~11 x 11或更大),函数使用基于DFT的算法;对于小内核,函数使用直接算法(使用“createLinearFilter”检索的引擎)。

代码示例

代码示例来源:origin: nroduit/Weasis

public static ImageCV filter(Mat source, KernelData kernel) {
  Objects.requireNonNull(kernel);
  Mat srcImg = Objects.requireNonNull(source);
  Mat k = new Mat(kernel.getHeight(), kernel.getWidth(), CvType.CV_32F);
  k.put(0, 0, kernel.getData());
  ImageCV dstImg = new ImageCV();
  Imgproc.filter2D(srcImg, dstImg, -1, k);
  // TODO improve speed with dedicated call
  // Imgproc.blur(srcImg, dstImg, new Size(3,3));
  return dstImg;
}

代码示例来源:origin: openpnp/openpnp

kernel.put(0, 0, 0, 1, -1, 0);
Mat roberts1 = new Mat();
Imgproc.filter2D(mat, roberts1, CvType.CV_32FC1, kernel);
Core.convertScaleAbs(roberts1, roberts1);
Imgproc.filter2D(mat, roberts2, CvType.CV_32FC1, kernel);
Core.convertScaleAbs(roberts2, roberts2);

代码示例来源:origin: openpnp/openpnp

@Override
  public Result process(CvPipeline pipeline) throws Exception {
    Mat mat = pipeline.getWorkingImage();

    Mat kernel = Mat.eye(new Size(2, 2), CvType.CV_32FC1);
    kernel.put(0, 0, 0, 1, -1, 0);
    Mat roberts1 = new Mat();
    Imgproc.filter2D(mat, roberts1, CvType.CV_32FC1, kernel);
    Core.convertScaleAbs(roberts1, roberts1);

    kernel.put(0, 0, 1, 0, 0, -1);
    Mat roberts2 = new Mat();
    Imgproc.filter2D(mat, roberts2, CvType.CV_32FC1, kernel);
    Core.convertScaleAbs(roberts2, roberts2);

    Mat roberts = new Mat();
    Core.add(roberts1, roberts2, roberts);
    
    kernel.release();
    roberts1.release();
    roberts2.release();

    return new Result(roberts);
  }
}

相关文章

微信公众号

最新文章

更多

Imgproc类方法