天天看点

HALCON示例程序find_pads.hdev通过fit_rectangle2_contour_xld绘制精准轮廓HALCON示例程序find_pads.hdev通过fit_rectangle2_contour_xld绘制精准轮廓

HALCON示例程序find_pads.hdev通过fit_rectangle2_contour_xld绘制精准轮廓

示例程序源码(加注释)

  • 关于显示类函数解释

    dev_update_pc (‘off’)

    dev_update_window (‘off’)

    dev_update_var (‘off’)

    read_image (Image, ‘die_pads’)

    dev_close_window ()

    get_image_size (Image, Width, Height)

    dev_open_window (0, 0, Width * 2, Height * 2, ‘black’, WindowHandle)

    dev_set_part (0, 0, Height - 1, Width - 1)

  • fast_threshold - 使用全局阈值快速阈值处理图像。
  • fast_threshold(图片:区域:最小灰度值,最大灰度值,最小阈值分割值:)

    fast_threshold (Image, Region, 180, 255, 20)

  • 分割连通域

    connection (Region, ConnectedRegions)

  • 使面积与长短轴比值筛选区域

    select_shape (ConnectedRegions, SelectedRegions, [‘area’,‘anisometry’], ‘and’, [200,1], [1200,2])

    fill_up (SelectedRegions, RegionFillUp)

  • 求取最大边界

    shape_trans (RegionFillUp, RegionTrans, ‘convex’)

  • boundary - 将区域缩小到其边界。
  • boundary(区域:区域边界:边界种类 ?

    boundary (RegionTrans, RegionBorder, ‘inner’)

  • 使用圆形元素对区域进行膨胀

    dilation_circle (RegionBorder, RegionDilation, 2.5)

    union1 (RegionDilation, RegionUnion)

  • 减少图片定义域

    reduce_domain (Image, RegionUnion, ImageReduced)

  • 求取边界

    edges_sub_pix (ImageReduced, Edges, ‘sobel_fast’, 0.5, 20, 40)

  • 使用长度筛选边界

    select_shape_xld (Edges, SelectedContours, ‘contlength’, ‘and’, 10, 200)

  • union_adjacent_contours_xld - 计算端点靠近的轮廓的并集。
  • union_adjacent_contours_xld(边缘:合并边缘:最大绝对距离,最大长度相对距离,模式:)

    union_adjacent_contours_xld (SelectedContours, UnionContours, 2, 1, ‘attr_keep’)

  • fit_rectangle2_contour_xld - 拟合XLD轮廓为矩形。

    fit_rectangle2_contour_xld (UnionContours, ‘tukey’, -1, 0, 0, 3, 2, Row, Column, Phi, Length1, Length2, PointOrder)

  • gen_rectangle2_contour_xld - 创建矩形形状的XLD轮廓。

    gen_rectangle2_contour_xld (Rectangle, Row, Column, Phi, Length1, Length2)

    dev_display (Image)

    dev_set_colored (12)

    dev_display (Rectangle)

处理思路

这个例子是主要讲解了如何利用边缘提取与矩形拟合进行精确定位。使用了fast_threshold进行阈值分割,boundary并dilation_circle得到边界图像,使用edges_sub_pix进行边缘提取,select_shape_xld筛选边界,fit_rectangle2_contour_xld边界矩形拟合,gen_rectangle2_contour_xld绘制边缘轮廓。

后记

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

继续阅读