halcon 历程注解 check_hazelnut_wafers.hdev

* 此示例演示了榛子饼干的质量检查。
* 利用形态学工具,根据一些形状特征,如矩形和区域孔,提取和检查波动。
* 该程序还显示了操作符area_holes的使用。

* This example demonstrates a quality inspection on hazelnut wavers.
* Using the morphology tools the waver is extracted and examined according to a few shape features like Rectangularity and AreaHoles.
* This program also shows the use of the operator area_holes.
* 
* 此示例演示了榛子饼干的质量检查。
* 利用形态学工具,根据一些形状特征,如矩形和区域孔,提取和检查波动。
* 该程序还显示了操作符area_holes的使用。
read_image (Image, 'food/hazelnut_wafer_01')
dev_close_window ()
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_update_window ('off')
dev_set_line_width (3)
dev_set_draw ('margin')
set_display_font (WindowHandle, 20, 'mono', 'true', 'false')
* 
for Index := 1 to 24 by 1
    read_image (Image, 'food/hazelnut_wafer_' + Index$'.02')
    * 使用二值阈值分割图像
    * ’max_separability’:最大限度的可分性, ‘smooth_histo’:直方图平滑。
    * 这两种方法只能用于具有双峰直方图的图像。
    * Method= ’ max_separability ',根据“灰度直方图的阈值选择方法”的灰度直方图自动阈值调用。该算法首先计算图像的直方图,然后利用统计矩找到将像素分割为前景和背景的最优阈值,并最大化这两个类之间的可分性。此方法仅适用于byte和uint2图像。
    binary_threshold (Image, Foreground, 'smooth_histo', 'light', UsedThreshold)
    opening_circle (Foreground, FinalRegion, 8.5)
    * 计算区域的孔洞面积
    * 得到饼干区域破损的面积
    area_holes (FinalRegion, AreaHoles)
    * 矩形度
    rectangularity (FinalRegion, Rectangularity)
    dev_display (Image)
    if (AreaHoles > 300 or Rectangularity < 0.92)
        dev_set_color ('red')
        Text := 'Not OK'
    else
        dev_set_color ('forest green')
        Text := 'OK'
    endif
    dev_display (FinalRegion)
    disp_message (WindowHandle, Text, 'window', -1, -1, '', 'false')
    if (Index < 24)
        disp_continue_message (WindowHandle, 'black', 'true')
        stop ()
    endif
endfor




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小菠萝0908

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值