HALCON示例程序fin.hdev通过形态学检测缺陷
示例程序源码(加注释)
- 关于显示类函数解释
 dev_update_window (‘off’)
 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)
 disp_continue_message (WindowID, ‘black’, ‘true’)
 stop ()
- 使用圆形元素进行闭运算
 closing_circle (Background, ClosedBackground, 250)
 dev_set_color (‘green’)
 dev_display (ClosedBackground)
 disp_continue_message (WindowID, ‘black’, ‘true’)
 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
 
- 使用二进制阈值分割图像
处理思路
这个例子是主要利用closing_circle、opening_rectangle1 前后的变换使用difference 求出差集,进而提取出缺陷。
后记
 大家有什么问题可以向我提问哈,我看到了第一时间回复,希望在学习的路上多多结交良师益友。