HALCON示例程序measure_ball_bond.hdev电路板焊点位置测量

HALCON示例程序measure_ball_bond.hdev电路板焊点位置测量

示例程序源码(加注释)

  • 关于显示类函数解释
    dev_update_off ()
    dev_close_window ()
    FileName := ‘bonds/ball_bond_ccd_’
    read_image (Image, FileName + 1$‘02’)
    dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
    dev_set_line_width (2)
    set_display_font (WindowHandle, 16, ‘mono’, ‘true’, ‘false’)
    dev_set_draw (‘margin’)
    get_system (‘store_empty_region’, StoreEmptyRegion)
    set_system (‘store_empty_region’, ‘false’)
  • 定义变量并初始化
    NumImages := 6
    for Index := 1 to NumImages by 1
    read_image (Image, FileName + Index$‘02’)
    dev_display (Image)
    • 获得运行时间
      count_seconds (S1)
    • 二值化
      threshold (Image, Region, 135, 255)
    • 分割连通域
      connection (Region, ConnectedRegions)
    • 使用宽度高度面积进行区域筛选
      select_shape (ConnectedRegions, SelectedRegions, [‘width’,‘height’,‘area’], ‘and’, [115,115,5000], [130,130,15000])
      fill_up (SelectedRegions, RegionFillUp)
      shape_trans (RegionFillUp, Pads, ‘convex’)
    • 求取内孔区域
      difference (Pads, RegionFillUp, RegionDifference)
    • 开运算
      opening_rectangle1 (RegionDifference, BondWire, 10, 10)
    • 求取最大内切圆
      shape_trans (BondWire, BallBonds, ‘inner_circle’)
    • select_shape_proto基于区域之间的某些关系选择区域,这里使用重叠区域
    • select_shape_proto(测量区域,对比区域:筛选出的区域:关系,最小值,最大值:)
      select_shape_proto (Pads, BallBonds, MissingBonds, ‘overlaps_rel’, 0, 0)
      count_seconds (S2)
      Time := (S2 - S1) * 1000
    • 膨胀
      dilation_circle (BallBonds, RegionDilation2, 10)
    • 求交集
      intersection (RegionDilation2, BondWire, RegionIntersection)
    • 求边缘的老方法了,之前的贴子传送门
      boundary (RegionIntersection, RegionBorder, ‘inner’)
      dilation_circle (RegionBorder, RegionDilation, 3.5)
      union1 (RegionDilation, RegionUnion)
      reduce_domain (Image, RegionUnion, ImageReduced)
      edges_sub_pix (ImageReduced, Edges, ‘canny’, 1, 20, 70)
    • union_adjacent_contours_xld - 计算端点靠近的轮廓的并集。
    • union_adjacent_contours_xld(边缘:合并的边缘:端点最大绝对阈值,端点最大相对阈值,模式:)
      union_adjacent_contours_xld (Edges, UnionContours, 10, 1, ‘attr_keep’)
    • 筛选XLD轮廓
      select_contours_xld (UnionContours, SelectedContours, ‘contour_length’, 20, 20000, -0.5, 0.5)
    • 通过XLD轮廓拟合圆形
      fit_circle_contour_xld (SelectedContours, ‘atukey’, -1, 0, 0, 5, 7, CircleRow, CircleColumn, Radius, StartPhi, EndPhi, PointOrder)
    • 绘制XLD轮廓圆形
      gen_circle_contour_xld (ContCircle, CircleRow, CircleColumn, Radius, 0, 6.28318, ‘positive’, 1)
      count_obj (BondWire, NBonds)
      gen_empty_obj (MeasureArrows)
    • 下边这些就非常简单的啦
      dev_display (Image)
      dev_set_color (‘cyan’)
      dev_display (ContCircle)
      dev_set_color (‘magenta’)
      area_center (RegionDilation2, Area, Row, Column)
      area_center (MissingBonds, AreaM, RowM, ColumnM)
      select_shape_proto (Pads, BallBonds, BallTooClose, ‘distance_contour’, 0, 10)
      area_center (BallTooClose, AreaB, RowB, ColumnB)
      dev_set_color (‘yellow’)
      dev_display (Pads)
      if (|AreaM| > 0 or |AreaB| > 0)
      dev_set_color (‘red’)
      dev_display (MissingBonds)
      dev_display (BallTooClose)
      for IndexE := 0 to |AreaM| - 1 by 1
      NRow := RowM[IndexE]
      NCol := ColumnM[IndexE]
      disp_message (WindowHandle, ‘Ball bond\nis missing’, ‘image’, NRow - 150, NCol - 110, ‘red’, ‘true’)
      endfor
      for IndexE := 0 to |AreaB| - 1 by 1
      NRow := RowB[IndexE]
      NCol := ColumnB[IndexE]
      disp_message (WindowHandle, ‘Ball bond is too\nclose to border’, ‘image’, NRow - 150, NCol - 150, ‘red’, ‘true’)
      endfor
      endif
      for IndexM := 1 to NBonds by 1
      select_obj (ContCircle, ObjectSelected, IndexM)
      • 求取XLD轮廓的最小外接矩形
        smallest_rectangle1_xld (ObjectSelected, minY, minX, maxY, maxX)
      • 求取XLD轮廓中心
        area_center_xld (ObjectSelected, Area1, Ybb, Xbb, PointOrder1)
      • 绘制XLD箭头
        gen_arrow_contour_xld (Arrow, Ybb, Xbb, minY, Xbb, 12, 12)
        concat_obj (MeasureArrows, Arrow, MeasureArrows)
        gen_arrow_contour_xld (Arrow, Ybb, Xbb, maxY, Xbb, 12, 12)
        concat_obj (MeasureArrows, Arrow, MeasureArrows)
        dev_set_color (‘green’)
        dev_display (MeasureArrows)
        select_obj (ContCircle, ObjectSelected, IndexM)
        area_center_xld (ObjectSelected, Area2, Ybb, Xbb, PointOrder2)
        disp_message (WindowHandle, (2 * Radius[IndexM - 1])KaTeX parse error: Expected 'EOF', got '\nin' at position 129: …ond(s) detected\̲n̲i̲n̲ ̲' + Time’.2f’ + ’ ms’, ‘window’, 12, 12, ‘black’, ‘true’)
    • Evaluate and display results
      if (Index != NumImages)
      disp_continue_message (WindowHandle, ‘black’, ‘true’)
      stop ()
      endif
      endfor
      set_system (‘store_empty_region’, StoreEmptyRegion)

处理思路

这个例子是主要讲解了使用blob分析方法,结合XLD轮廓拟合,对电路焊点的检测与测量。count_seconds计时算子select_shape_proto、union_adjacent_contours_xld、select_contours_xld、fit_circle_contour_xld、gen_circle_contour_xld、gen_arrow_contour_xld、smallest_rectangle1_xld、area_center_xld、gen_arrow_contour_xld

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

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值