Halcon 笔记3 形态学

Halcon 三大数据类型:

(1)图像

(2)区域

(3)XLD

 查看时间工具

如果想让图像减少,则进行腐蚀(或者使用开运算),反之,则进行膨胀(或闭运算)

腐蚀后再进行膨胀,相当于进行开运算。因为腐蚀比膨胀去掉的更多。

erosion_circle (WiresFilled, RegionErosion, 15.5)
dilation_circle (RegionErosion, RegionDilation, 15.5)
opening_circle (WiresFilled, Balls, 15.5)//使用圆形的腐蚀,对圆形的作用比较大,如果比较圆的话,则保留

opening或者二值化得到的都是一个区域。

Blob分析典型实例

分割电路板焊点

 

* ball.hdev: Inspection of Ball Bonding
* 
dev_update_window ('off')
dev_close_window ()
dev_open_window (0, 0, 728, 512, 'black', WindowID)
read_image (Bond, 'die/die_03')
dev_display (Bond)
set_display_font (WindowID, 14, 'mono', 'true', 'false')
disp_continue_message (WindowID, 'black', 'true')
stop ()
threshold (Bond, Bright, 100, 255) //二值化
shape_trans (Bright, Die, 'rectangle2') //将区域进行形状转换,rectangle1表示不带方向
dev_set_color ('green')
dev_set_line_width (3)
dev_set_draw ('margin') //使用边缘描述模式
dev_display (Die)
disp_continue_message (WindowID, 'black', 'true')
stop ()
reduce_domain (Bond, Die, DieGrey)//抠图,在抠出的图中进行处理
threshold (DieGrey, Wires, 0, 50) //二值化
*fill_up是不带特征的填充,不管空洞有多大,都会进行填充
fill_up_shape (Wires, WiresFilled, 'area', 1, 100)//填充空洞,仅对面积在1到100之间的空洞进行填充
dev_display (Bond)
dev_set_draw ('fill')
dev_set_color ('red')
dev_display (WiresFilled)
disp_continue_message (WindowID, 'black', 'true')
stop ()
*opening 开运算,对应图像腐蚀
erosion_circle (WiresFilled, RegionErosion, 15.5)
dilation_circle (RegionErosion, RegionDilation, 15.5)
opening_circle (WiresFilled, Balls, 15.5)//使用圆形的腐蚀,对圆形的作用比较大,如果比较圆的话,则保留
dev_set_color ('green')
dev_display (Balls)
*dev_display (RegionDilation)
disp_continue_message (WindowID, 'black', 'true')
stop ()
connection (Balls, SingleBalls)//区域打散
select_shape (SingleBalls, IntermediateBalls, 'circularity', 'and', 0.85, 1.0)//形状选择
sort_region (IntermediateBalls, FinalBalls, 'first_point', 'true', 'column')//根据位置标定
dev_display (Bond)
dev_set_colored (12)
dev_display (FinalBalls)
disp_continue_message (WindowID, 'black', 'true')
stop ()
smallest_circle (FinalBalls, Row, Column, Radius) //根据像素直径标定
NumBalls := |Radius|
Diameter := 2 * Radius
meanDiameter := sum(Diameter) / NumBalls
mimDiameter := min(Diameter)
dev_display (Bond)
disp_circle (WindowID, Row, Column, Radius)
dev_set_color ('white')
disp_message (WindowID, 'D: ' + Diameter$'.4', 'image', Row - 2 * Radius, Column, 'white', 'false')
dev_update_window ('on')

 

 

 

实践是检验真理的唯一标准

posted @ 2017-12-29 18:04  mCat  Views(1448)  Comments(0Edit  收藏  举报