Haclon学习---饼干完整度检测

    技术2022-07-15  60

    check_hazelnut_wafers.hdev

    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') *使用二进制阈值分割图像 binary_threshold (Image, Foreground, 'smooth_histo', 'light', UsedThreshold) *对选取区域使用圆形区域进行开运算 opening_circle (Foreground, FinalRegion, 8.5) *计算区域的孔面积 *这个面积定义为孔中包含的像素数 *如果一个区域有多个孔,则返回该区域中所有孔的面积之和 area_holes (FinalRegion, AreaHoles) *求取区域的矩形度 rectangularity (FinalRegion, Rectangularity) dev_display (Image) *如果孔洞过多面积超过300或者矩形度小于0.92,认为破损 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

    Processed: 0.015, SQL: 9