【问题标题】:Image processing with opening and closing using emgu 3.0, MorphologyEx, c#使用 emgu 3.0、MorphologyEx、c# 打开和关闭的图像处理
【发布时间】:2017-01-14 00:38:25
【问题描述】:

如何使用新的emgu版本实现带开闭的图像处理?

我找到了这个: www.stackoverflow.com/questions/11567350/opening-and-closing-using-opencv/

但我不能再使用“StructuringElementEx”了,新的“image.MorphologyEx()”方法需要更多的值。

我也尝试过使用 .dilate 和 .erode ,但这仅适用于 3x3 矩形,但不太成功。

一个“更新”的例子会很棒!

【问题讨论】:

    标签: c# opencv emgucv background-subtraction


    【解决方案1】:

    您在使用 Emgu CV 3.0 的 MorphologyEx 时也遇到了同样的问题
    我在Github中找到了这个测试代码。
    希望对您有所帮助!

    [Test]
      public void TestMorphEx()
      {
         Mat kernel1 = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Cross, new Size(3, 3), new Point(1, 1));
         Matrix<byte> kernel2 = new Matrix<byte>(new Byte[3, 3] { { 0, 1, 0 }, { 1, 0, 1 }, { 0, 1, 0 } });
         //StructuringElementEx element2 = new StructuringElementEx(new int[3, 3] { { 0, 1, 0 }, { 1, 0, 1 }, { 0, 1, 0 } }, 1, 1);
         Image<Bgr, Byte> tmp = new Image<Bgr, byte>(100, 100);
         Image<Bgr, Byte> tmp2 = tmp.MorphologyEx(Emgu.CV.CvEnum.MorphOp.Gradient, kernel1, new Point(-1, -1), 1, CvEnum.BorderType.Default, new MCvScalar());
         Image<Bgr, Byte> tmp3 = tmp.MorphologyEx(Emgu.CV.CvEnum.MorphOp.Gradient, kernel2, new Point(-1, -1), 1, CvEnum.BorderType.Default, new MCvScalar());
         //Image<Bgr, Byte> tmp2 = tmp.MorphologyEx(element1, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_GRADIENT, 1);
         //Image<Bgr, Byte> tmp3 = tmp.MorphologyEx(element2, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_BLACKHAT, 1);
      }
    

    【讨论】:

      【解决方案2】:

      此函数在 EMGU 3.1 中不会使用 Mat

      我正在使用这个。

      // Opening (erode->dilate) para quitar ruido.
      // get rid of small objects
      Mat kernelOp = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3,3), new Point(-1, -1));
      CvInvoke.MorphologyEx(ThresholdMask, _Morphology, MorphOp.Open, kernelOp, new Point(-1, -1), 1, BorderType.Default, new MCvScalar());
      
      // Closing (dilate -> erode) para juntar regiones blancas.
      Mat kernelCl = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(11, 11), new Point(-1, -1));
      CvInvoke.MorphologyEx(_Morphology, _Morphology, MorphOp.Close, kernelCl, new Point(-1, -1), 1, BorderType.Default, new MCvScalar());
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-01-05
        • 2014-08-27
        • 2011-02-28
        • 1970-01-01
        • 2016-08-11
        • 1970-01-01
        • 1970-01-01
        • 2012-02-22
        相关资源
        最近更新 更多