HALCON示例程序measure_chip.hdev芯片封装检测

HALCON示例程序measure_chip.hdev芯片封装检测

示例程序源码(加注释)

  • 关于显示类函数解释
    dev_update_off ()
    read_image (Image, ‘die_on_chip’)
    get_image_size (Image, Width, Height)
    dev_close_window ()
    dev_open_window (0, 0, Width * 2, Height * 2, ‘light gray’, WindowID)
    dev_set_part (0, 0, Height - 1, Width - 1)
    dev_set_line_width (3)
    dev_set_color (‘white’)
    dev_set_draw (‘margin’)
    dev_display (Image)
    set_display_font (WindowID, 16, ‘mono’, ‘true’, ‘false’)
    dev_set_line_width (2)
    dev_set_draw (‘fill’)
  • 快速二值化
    fast_threshold (Image, Region, 120, 255, 20)
  • 开运算
    opening_rectangle1 (Region, RegionOpening, 4, 4)
  • 分割连通域
    connection (RegionOpening, ConnectedRegions)
  • 填充孔洞
    fill_up (ConnectedRegions, RegionFillUp)
  • 通过矩形度与面积筛选区域
    select_shape (RegionFillUp, SelectedRegions, [‘rectangularity’,‘area’], ‘and’, [0.8,700], [1,99999])
  • 求取可旋转最小外接矩形
    smallest_rectangle2 (SelectedRegions, Row, Column, Phi, Length1, Length2)
    gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2)
  • 求边界,膨胀,减小定义域。以达到提取定义域效果。
    boundary (Rectangle, RegionBorder, ‘inner_filled’)
    dilation_rectangle1 (RegionBorder, RegionDilation, 4, 4)
    reduce_domain (Image, RegionDilation, ImageReduced)
    dev_clear_window ()
    dev_display (ImageReduced)
    disp_continue_message (WindowID, ‘black’, ‘true’)
    stop ()
  • 使用canny算子提取边缘
    edges_sub_pix (ImageReduced, Edges, ‘canny’, 1.5, 30, 40)
  • 分割XLD轮廓,算子解释传送门
    segment_contours_xld (Edges, ContoursSplit, ‘lines’, 5, 2, 2)
  • 通过长度筛选边缘
    select_contours_xld (ContoursSplit, SelectedContours1, ‘contour_length’, 10, 99999, -0.5, 0.5)
  • 合并临近的XLD轮廓
    union_adjacent_contours_xld (SelectedContours1, UnionContours1, 30, 1, ‘attr_keep’)
  • 拟合最小外接矩形
    fit_rectangle2_contour_xld (UnionContours1, ‘tukey’, -1, 0, 0, 3, 2, Row1, Column1, Phi1, Length11, Length12, PointOrder1)
  • 绘制XLD最小外接矩形
    gen_rectangle2_contour_xld (Rectangle1, Row1, Column1, Phi1, Length11, Length12)
  • 下边一段代码与上边一样哈
    fast_threshold (Image, Region1, 65, 255, 20)
    connection (Region1, ConnectedRegions1)
    opening_rectangle1 (ConnectedRegions1, RegionOpening1, 10, 10)
    fill_up (RegionOpening1, RegionFillUp1)
    select_shape (RegionFillUp1, SelectedRegions1, ‘area’, ‘and’, 1000, 99999)
    boundary (SelectedRegions1, RegionBorder1, ‘inner’)
    dilation_rectangle1 (RegionBorder1, RegionDilation1, 10, 10)
    reduce_domain (Image, RegionDilation1, ImageReduced1)
    dev_clear_window ()
    dev_display (ImageReduced1)
    disp_continue_message (WindowID, ‘black’, ‘true’)
    stop ()
    threshold_sub_pix (ImageReduced1, Border1, 70)
    segment_contours_xld (Border1, ContoursSplit2, ‘lines’, 5, 2, 2)
    select_contours_xld (ContoursSplit2, SelectedContours2, ‘contour_length’, 30, 99999, -0.5, 0.5)
    union_adjacent_contours_xld (SelectedContours2, UnionContours2, 30, 1, ‘attr_keep’)
    fit_rectangle2_contour_xld (UnionContours2, ‘tukey’, -1, 0, 0, 3, 2, Row2, Column2, Phi2, Length21, Length22, PointOrder2)
    gen_rectangle2_contour_xld (Rectangle2, Row2, Column2, Phi2, Length21, Length22)
    dev_clear_window ()
    dev_set_colored (3)
  • dev_display (Image)
    dev_display (SelectedContours1)
    dev_display (SelectedContours2)
    disp_continue_message (WindowID, ‘black’, ‘true’)
    stop ()
    dev_set_color (‘white’)
    dev_display (UnionContours1)
    dev_set_color (‘yellow’)
    dev_display (UnionContours2)
    disp_continue_message (WindowID, ‘black’, ‘true’)
    stop ()
    dev_display (Image)
    dev_set_color (‘white’)
    dev_display (Rectangle1)
    gen_cross_contour_xld (Cross1, Row1, Column1, 6, Phi1)
    dev_display (Cross1)
    dev_set_color (‘yellow’)
    dev_display (Rectangle2)
    gen_cross_contour_xld (Cross2, Row2, Column2, 6, Phi2)
    dev_display (Cross2)
    distance_pp (Row1, Column1, Row2, Column2, Distance)
    DifferenceOrientation := Phi1 - Phi2
    set_tposition (WindowID, 10, 10)
    write_string (WindowID, ‘Distance between centers: ’ + Distance ′ . 3 ′ + ′ p i x e l ′ ) s e t t p o s i t i o n ( W i n d o w I D , 25 , 10 ) w r i t e s t r i n g ( W i n d o w I D , ′ D i f f e r e n c e b e t w e e n o r i e n t a t i o n s : ′ + d e g ( D i f f e r e n c e O r i e n t a t i o n ) '.3' + ' pixel') set_tposition (WindowID, 25, 10) write_string (WindowID, 'Difference between orientations: ' + deg(DifferenceOrientation) .3+pixel)settposition(WindowID,25,10)writestring(WindowID,Differencebetweenorientations:+deg(DifferenceOrientation)’.2’ + ’ deg’)
    dev_update_window (‘on’)

处理思路

这个例子是主要讲解了矩形边缘的拟合。

后记

大家有什么问题可以向我提问哈,我看到了第一时间回复,希望在学习的路上多多结交良师益友。

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值