基于vb.net emgucv形态学(开、闭、腐蚀、膨胀)操作

昨天被问到关于基于vb.net       emgucv形态学(开、闭、腐蚀、膨胀)操作,网上VB.net资料也太少了,在这里我就把他整理成一个函数,方便使用vb.net的同志直接调用。形态学(开、闭、腐蚀、膨胀)的具体意义、目的我在这里就不啰嗦了,网上一搜一大把。

具体函数如下:

形态学操作函数 imagecloseopen:其中 picturebox1输入图像, picturebox2为输出图像,iselect为选择开、闭、腐蚀、膨胀,可选择“0,1,2,3”,用了try-Catch容错语句,同志们可以去掉,返回值为string,正确返回“1”,错误返回“0”

 

Public Shared Function imagecloseopen(ByVal As PictureBox, ByVal picturebox2 As PictureBox, ByVal iselect As Int16) As String
        Try
            Dim img As Image(Of Bgr, Byte) = New Image(Of Bgr, Byte)(picturebox1.Image)
            Dim img_threshold As Image(Of Bgr, Byte) = New Image(Of Bgr, Byte)(img.Width, img.Height)

            Dim img_element As Mat = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Ellipse, New Size(3, 3), New Point(-1, -1))
            If iselect = 0 Then
                CvInvoke.MorphologyEx(img, img_threshold, MorphOp.Close, img_element, New Point(-1, -1), 5, BorderType.Default, New MCvScalar(0, 0, 0))
            ElseIf iselect = 1 Then
                CvInvoke.MorphologyEx(img, img_threshold, MorphOp.Open, img_element, New Point(-1, -1), 9, BorderType.Default, New MCvScalar(0, 0, 0))
            ElseIf iselect = 3 Then 
                CvInvoke.MorphologyEx(img, img_threshold, MorphOp.Erode, img_element, New Point(-1, -1), 2, BorderType.Default, New MCvScalar(0, 0, 0))
            ElseIf iselect = 2 Then 
                CvInvoke.MorphologyEx(img, img_threshold, MorphOp.Dilate, img_element, New Point(-1, -1), 2, BorderType.Default, New MCvScalar(0, 0, 0))
            End If

            picturebox2.Image = img_threshold.ToBitmap()
            picturebox2.SizeMode = PictureBoxSizeMode.Zoom

            Return 1
        Catch ex As Exception
            Return 0
        End Try

    End Function

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值