Blob分析之ball_seq.hdev

 

* 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')
*设置显示填充形式,两种,margin表示边界,fill表示全部填充
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)
       *右下角显示 'Press Run (F5) to continue' 这个信息
        disp_continue_message (WindowHandle, 'black', 'true')
    endif
    stop ()
endfor

posted @ 2020-07-27 14:06  懒树懒  阅读(227)  评论(0)    收藏  举报