产品毛刺检测
毛刺检测.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