1 * ball.hdev: Inspection of Ball Bonding 2 * 球接合检查 Comment Time:2014/9/10 3 *核心思想:1.白色区域用作自动ROI,黑色区域是目标 4 * 2.Opening_circle:圆形开算子是关键 5 *关闭窗口刷新,关闭窗口,打开窗口[728,512] 6 dev_update_window (‘off‘) 7 dev_close_window () 8 dev_open_window (0, 0, 728, 512, ‘black‘, WindowID) 9 *读取图像并显示 10 read_image (Bond, ‘die/die_03‘) 11 dev_display (Bond) 12 set_display_font (WindowID, 14, ‘mono‘, ‘true‘, ‘false‘) 13 *显示F5提示信息并暂停 14 disp_continue_message (WindowID, ‘black‘, ‘true‘) 15 stop () 16 *固定二值化,取白色区域部分 17 threshold (Bond, Bright, 100, 255) 18 *将所有区域变换成最小的外接矩形,相当于做ROI 19 shape_trans (Bright, Die, ‘rectangle2‘) 20 *设置显示方式:绿色,边缘模式,线条宽度3 21 dev_set_color (‘green‘) 22 dev_set_line_width (3) 23 dev_set_draw (‘margin‘) 24 dev_display (Die) 25 disp_continue_message (WindowID, ‘black‘, ‘true‘) 26 stop () 27 *利用生成的外接矩形做ROI 28 reduce_domain (Bond, Die, DieGrey) 29 *在ROI中二值化取黑色区域,并按面积标准填充 30 threshold (DieGrey, Wires, 0, 50) 31 fill_up_shape (Wires, WiresFilled, ‘area‘, 1, 100) 32 *设置显示模式:填充模式,红色 33 dev_display (Bond) 34 dev_set_draw (‘fill‘) 35 dev_set_color (‘red‘) 36 dev_display (WiresFilled) 37 disp_continue_message (WindowID, ‘black‘, ‘true‘) 38 stop () 39 *圆形式的开运算:先腐蚀后膨胀,消除颗粒(精髓算子) 40 opening_circle (WiresFilled, Balls, 15.5) 41 dev_set_color (‘green‘) 42 dev_display (Balls) 43 disp_continue_message (WindowID, ‘black‘, ‘true‘) 44 stop () 45 *单个区域连接成区域数组 46 connection (Balls, SingleBalls) 47 *按圆度来进行区域的筛选,完成定位功能 48 select_shape (SingleBalls, IntermediateBalls, ‘circularity‘, ‘and‘, 0.85, 1.0) 49 *已OK的区域进行从左至右排序 50 sort_region (IntermediateBalls, FinalBalls, ‘first_point‘, ‘true‘, ‘column‘) 51 dev_display (Bond) 52 dev_set_colored (12) 53 dev_display (FinalBalls) 54 disp_continue_message (WindowID, ‘black‘, ‘true‘) 55 stop () 56 *求区域的最小外接圆 57 smallest_circle (FinalBalls, Row, Column, Radius) 58 NumBalls := |Radius| 59 Diameter := 2*Radius 60 meanDiameter := sum(Diameter)/NumBalls 61 mimDiameter := min(Diameter) 62 dev_display (Bond) 63 *显示最小外接圆 64 disp_circle (WindowID, Row, Column, Radius) 65 *书写文字标识 66 dev_set_color (‘white‘) 67 for i := 1 to NumBalls by 1 68 if (fmod(i,2)=1) 69 disp_message (WindowID, ‘D: ‘+Diameter[i-1], ‘image‘, Row[i-1]-2.7*Radius[i-1], max([Column[i-1]-60,0]), ‘white‘, ‘false‘) 70 else 71 disp_message (WindowID, ‘D: ‘+Diameter[i-1], ‘image‘, Row[i-1]+1.2*Radius[i-1], max([Column[i-1]-60,0]), ‘white‘, ‘false‘) 72 endif 73 endfor 74 *关闭窗口 75 * dump_window (WindowID, ‘tiff_rgb‘, ‘./ball‘) 76 dev_set_color (‘green‘) 77 dev_update_window (‘on‘) 78 disp_continue_message (WindowID, ‘black‘, ‘true‘) 79 stop () 80 dev_close_window ()
时间: 2024-10-12 12:15:26