简体   繁体   English

在Emgu中使用Erode和Dilate(适用于C#的OpenCV)

[英]Using Erode and Dilate in Emgu (OpenCV for C#)

Unlike the python bindings for the OpenCv Dilate function, the C# version has more arguments that are all mandatory, and I'm not sure what to use for the elements for the element argument. 与OpenCv Dilate函数的python绑定不同,C#版本具有更多都是强制性的参数,并且我不确定用于element参数元素的内容。 I tried the following, and the output looks identical to the inpur: 我尝试了以下操作,并且输出看起来与inpur相同:

public static void Dilate(
    IInputArray src,
    IOutputArray dst,
    IInputArray element,
    Point anchor,
    int iterations,
    BorderType borderType,
    MCvScalar borderValue
)

In Python I would do something like: 在Python中,我将执行以下操作:

kernel = np.ones((5,5),np.uint8)

dilation = cv2.dilate(src, kernel,iterations=3)

In C#, I tried using the Default values. 在C#中,我尝试使用默认值。 but the output does not look any different than the input. 但输出看起来与输入没有什么不同。

    ScalarArray elem = new ScalarArray(0);

    CvInvoke.Dilate(_cannyFrame
             , _dilatedCanny
             , elem
             , new Point(-1,- 1)
             , 6
             , BorderType.Constant 
             , new MCvScalar(255, 255, 255) );    

The error seems to be in the structuring element. 错误似乎在结构元素中。 You are using an elem equal to zero and this has no effect on destination image _dilatedCanny . 您使用的elem等于零,这对目标图像_dilatedCanny In python you are using a kernel with ones element... 在python中,您正在使用具有一个元素的内核...

Try this 尝试这个

Mat element = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Rectangle, new Size(3, 3), new Point(-1, -1));

CvInvoke.Dilate(_cannyFrame
         , _dilatedCanny
         , element 
         , new Point(-1,- 1)
         , 6
         , BorderType.Constant 
         , new MCvScalar(255, 255, 255) );   

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

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