在前一篇文章(ball.hdev)已经介绍了焊点检测的大致方法,这篇文章主要介绍(ball_seq.hdev)采用的方法有何改进,以及背后的原因。
方法不同之处1
对比代码发现原来是直接使用size为15.5的圆进行开运算获取焊点圆,而这里size为9.5。
opening_circle (WiresFilled, Balls, 9.5)
connection (Balls, SingleBalls)
select_shape_std (SingleBalls, Rect, 'rectangle1', 90)
difference (SingleBalls, Rect, IntermediateBalls)
gen_empty_region (Forbidden)
expand_gray (IntermediateBalls, Bond, Forbidden, RegionExpand, 4, 'image', 6)
opening_circle (RegionExpand, RoundBalls, 15.5)
观察图像发现分割后的区域有一个与焊点大小近似的矩形区域(下图蓝色框),而之前的测试图像没有。
如果这里使用size为15.5的开运算会导致矩形膨胀后为原型不利于后续的分割。所以这里采用size=9.5进行开运算
方法不同之处2
在获取焊点区域后使用了expand_gray算子(区域外扩到灰度相似区域),认为是通过使用expand_gray提高区域的准确性(但我通过图像看感觉扩展后更差了)。
未扩展前:
扩展后:
完整代码如下
* ball_seq.hdev: Inspection of Ball Bonding
*
dev_update_off ()
ImageNames := 'die/' + ['die_02','die_03','die_04','die_07']
dev_set_colored (12)
read_image (Bond, ImageNames[0])
get_image_size (Bond, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (3)
NumImages := |ImageNames|
for I := 0 to NumImages - 1 by 1
read_image (Bond, ImageNames[I])
dev_display (Bond)
min_max_gray (Bond, Bond, 0, Min, Max, Range)
threshold (Bond, Bright, Max - 80, 255)
shape_trans (Bright, Die, 'rectangle2')
dev_display (Die)
reduce_domain (Bond, Die, DieGrey)
min_max_gray (Die, Bond, 0, Min, Max, Range)
threshold (DieGrey, Wires, 0, Min + 30)
fill_up_shape (Wires, WiresFilled, 'area', 1, 100)
opening_circle (WiresFilled, Balls, 9.5)
connection (Balls, SingleBalls)
select_shape_std (SingleBalls, Rect, 'rectangle1', 90)
difference (SingleBalls, Rect, IntermediateBalls)
gen_empty_region (Forbidden)
expand_gray (IntermediateBalls, Bond, Forbidden, RegionExpand, 4, 'image', 6)
opening_circle (RegionExpand, RoundBalls, 15.5)
sort_region (RoundBalls, FinalBalls, 'first_point', 'true', 'column')
smallest_circle (FinalBalls, Row, Column, Radius)
NumBalls := |Radius|
Diameter := 2 * Radius
meanDiameter := sum(Diameter) / NumBalls
mimDiameter := min(Diameter)
dev_display (RoundBalls)
if (I != NumImages)
disp_continue_message (WindowHandle, 'black', 'true')
endif
stop ()
endfor