Halcon缺陷检测之产品毛刺检测

产品毛刺检测

毛刺检测.hdev

// fin.hdev: Detection of a fin
//关闭程序计数器,变量更新,图像更新窗口
dev_update_window ('off')
//一次性读取3张图像
read_image (Fins, 'fin' + [1:3])
//获取图像宽高
get_image_size (Fins, Width, Height)
//关闭窗口
dev_close_window ()
//打开窗口
dev_open_window (0, 0, Width[0], Height[0], 'black', WindowID)
//设置字体信息
set_display_font (WindowID, 14, 'mono', 'true', 'false')
for I := 1 to 3 by 1
    //选择图像集合里的指定索引的图像
    select_obj (Fins, Fin, I)
    //显示图像
    dev_display (Fin)
    //图像二值化,获取背景为亮的区域
    binary_threshold (Fin, Background, 'max_separability', 'light', UsedThreshold)
    //设置输出对象颜色
    dev_set_color ('blue')
    //设置区域填充模式
    dev_set_draw ('margin')
    //设置输出对象的线宽
    dev_set_line_width (4)
    //显示背景区域
    dev_display (Background)
    //对区域闭运算
    closing_circle (Background, ClosedBackground, 250)
    //设置输出对象的颜色
    dev_set_color ('green')
    //显示闭运算区域
    dev_display (ClosedBackground)
    stop ()
    //闭运算区域和背景区域
    difference (ClosedBackground, Background, RegionDifference)
    //开运算消除边缘周边毛刺
    opening_rectangle1 (RegionDifference, FinRegion, 5, 5)
    //显示图像
    dev_display (Fin)
    //设置输出对象的颜色
    dev_set_color ('red')
    //显示最终的毛刺区域
    dev_display (FinRegion)
    //获取区域的面积,中心行坐标,中心列坐标
    area_center (FinRegion, FinArea, Row, Column)
    if (I < 3)
        disp_continue_message (WindowID, 'black', 'true')
        stop ()
    endif
endfor
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值