简体   繁体   English

opencv4android中的filter2d

[英]filter2d in opencv4android

I'm trying to write a simple code in opencv4android using filter2d. 我正在尝试使用filter2d在opencv4android中编写一个简单的代码。 but after calling the function 'filter2d', in the destination mat, i get zeros (it didn't run the function correctly). 但在调用函数'filter2d'后,在目标mat中,我得到零(它没有正确运行该函数)。

the result should be: 结果应该是:

  0.3750    0.5000    0.5000    0.5000    0.3750
       0         0         0         0         0
       0         0         0         0         0
       0         0         0         0         0
 -0.3750   -0.5000   -0.5000   -0.5000   -0.3750

i tried changing the source's and kernel's depth/type but it didn't help. 我尝试更改源代码和内核的深度/类型,但它没有帮助。

here's my code: 这是我的代码:

    Mat sourceMat = new Mat(5, 5, CvType.CV_32F);
    Mat convMat = new Mat(3, 3, CvType.CV_32F);
    Mat destMat = Mat.zeros(5, 5, CvType.CV_32F);

    sourceMat.put(0,0,1);
    sourceMat.put(0,1,1);
    sourceMat.put(0,2,1);
    sourceMat.put(0,3,1);
    sourceMat.put(0,4,1);
    sourceMat.put(1,0,1);
    sourceMat.put(1,1,1);
    sourceMat.put(1,2,1);
    sourceMat.put(1,3,1);
    sourceMat.put(1,4,1);
    sourceMat.put(2,0,1);
    sourceMat.put(2,1,1);
    sourceMat.put(2,2,1);
    sourceMat.put(2,3,1);
    sourceMat.put(2,4,1);
    sourceMat.put(3,0,1);
    sourceMat.put(3,1,1);
    sourceMat.put(3,2,1);
    sourceMat.put(3,3,1);
    sourceMat.put(3,4,1);
    sourceMat.put(4,0,1);
    sourceMat.put(4,1,1);
    sourceMat.put(4,2,1);
    sourceMat.put(4,3,1);
    sourceMat.put(4,4,1);

    convMat.put(0,0, 0.125);
    convMat.put(0,1, 0.5);
    convMat.put(0,2, 0.125);
    convMat.put(1,0, 0);
    convMat.put(1,1, 0);
    convMat.put(1,2, 0);
    convMat.put(2,0, -0.125);
    convMat.put(2,1, -0.5);
    convMat.put(2,2, -0.125);


    Imgproc.filter2D(sourceMat, destMat, sourceMat.depth(), convMat);

Can anyone tell my what's the problem here? 谁能告诉我这里的问题是什么? is there something i'm doing wrong? 有什么我做错了吗?

Nothing wrong here. 这里没有错。 OpenCV result is correct for the default border handling mode used in filter2d function. OpenCV结果对于filter2d函数中使用的默认边界处理模式是正确的。

You need to set the last borderType parameter to Imgproc.BORDER_CONSTANT to get your expected result. 您需要将最后一个borderType参数设置为Imgproc.BORDER_CONSTANT以获得预期结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM