HALCON示例程序inspect_solar_fingers.hdev太阳能电池板电路缺陷检测

HALCON示例程序inspect_solar_fingers.hdev太阳能电池板电路缺陷检测

示例程序源码(加注释)

  • 关于显示类函数解释
    dev_update_off ()
    dev_close_window ()
    ImageName := ‘solar_cell/solar_cell_’
    read_image (Image, ImageName + ‘01’)
    dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
    set_display_font (WindowHandle, 14, ‘mono’, ‘true’, ‘false’)
    dev_set_color (‘red’)
    dev_set_draw (‘margin’)
    dev_set_line_width (2)
    NumImages := 6
    for Index := 1 to NumImages by 1
    read_image (Image, ImageName + Index$‘02’)
    • 彩色图像分成RGB三个通道
      decompose3 (Image, ImageR, ImageG, ImageB)
    • 二值化
      threshold (ImageR, Region, 0, 159)
      *分割连通域
      connection (Region, ConnectedRegions)
    • 使用宽度、高度、面积对区域进行筛选
      select_shape (ConnectedRegions, GoodSmallParts, [‘area’,‘width’], ‘and’, [3500,130], [5000,300])
      select_shape (ConnectedRegions, GoodLongParts, [‘area’,‘width’], ‘and’, [6000,350], [10000,550])
      select_shape (ConnectedRegions, Clutter, [‘width’,‘height’,‘area’], ‘or’, [900,900,0], [1000,1000,100])
    • 求取筛选出的与合格的不同的区域
      difference (ConnectedRegions, GoodSmallParts, Difference)
      difference (Difference, GoodLongParts, Difference)
      difference (Difference, Clutter, BrokenParts)
    • 对不合格区域进行形状变换,变换为矩形
      shape_trans (BrokenParts, BrokenPartsTrans, ‘rectangle1’)
    • 合格的部分高度大概在19,用高为25的矩形进行腐蚀,那么断开区域就能被筛选出来了
      erosion_rectangle1 (BrokenParts, RegionErosion, 1, 25)
      connection (RegionErosion, ConnectedBreaks)
    • 求区域的最小外接圆
      shape_trans (ConnectedBreaks, Breaks, ‘outer_circle’)
    • 膨胀一下
      dilation_circle (Breaks, Breaks, 6)
    • 删除空区域
      select_shape (Breaks, Breaks, ‘area’, ‘and’, 1, 99999999)
      count_obj (Breaks, CountBreaks)
      dev_display (Image)
      dev_display (BrokenPartsTrans)
      dev_display (Breaks)
    if (CountBreaks == 0)
    disp_message (WindowHandle, ‘Cell OK’, ‘window’, 12, 12, ‘black’, ‘true’)
    else
    disp_message (WindowHandle, ‘Cell not OK’, ‘window’, 12, 12, ‘red’, ‘true’)
    endif
    *
    if (Index != NumImages)
    disp_continue_message (WindowHandle, ‘black’, ‘true’)
    stop ()
    endif
    • 如果只有一处缺陷,放大显示
      if (CountBreaks == 1)
      dev_open_window (0, 610, 300, 300, ‘black’, WindowHandle1)
      area_center (Breaks, Area, Row, Column)
      dev_set_part (Row[0] - 50, Column[0] - 50, Row[0] + 50, Column[0] + 50)
      dev_display (Image)
      dev_display (BrokenPartsTrans)
      dev_display (Breaks)
      stop ()
      dev_set_window (WindowHandle1)
      dev_close_window ()
      endif
      endfor

处理思路

这个例子是主要讲解了太阳能电池板的电路完整性检测。灵活的应用了select_shape 与difference ;shape_trans完成了缺陷区域的框选;erosion_rectangle1 腐蚀缺陷区域以提取断点。

后记

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

你可能感兴趣的:(#,Halcon示例程序解读与剖析)