• HALCON-从入门到入门-阈值分割定位算子综合运用


    1.废话

    之前我的一个师兄告诉我,针对图像上想要定位的内容,机器视觉中定位的方式有很多种,但是如果用阈值分割定位可以做的,就不要用模板匹配了。因为基于形状的模板匹配始终会存在匹配不到的风险,那如果打光效果可以,阈值分割定位的效果就会稳定很多。

    其实可以分为两种情况:

    第一种,使用背光打出来的图像,图像边缘非常锋利,且形状一致性比较强,周围背景色块干扰比较多,这种情况我们考虑形状给模板匹配

    第二种,产品正面打光,边缘存在过渡像素,周围背景色块干扰小,形状差异较大,这种我们考虑阈值分割进行产品定位。

    后面慢慢学习过来之后就发现,在实际上很多的项目中,打光出来的成像效果在边缘都不是非常清晰,过渡非常明显的,由于产品一致性的原因,很多时候拍照出来产品的形状也会发生变换,那么我们使用阈值分割会比较稳定一些。

    2.实现效果

    下面是阈值分割的效果图。

    这是一张芯片引脚的图片,案例的目的是将引脚的焊点定位出来。

    其中用到的算子就都是二值化,形状选择,形态学操作的组合。

    3.代码解析

    1.首先第一步读取图片

    read_image (Bond, ImageNames[I])

    2.获取整个图像上的灰度最大最小值

        min_max_gray (Die, Bond, 0, Min, Max, Range)

    3.基于灰度最小值,二值化出黑色部分像素

        threshold (DieGrey, Wires, 0, Min + 30)

    4.对得到的区域进行开运算

        opening_circle (WiresFilled, Balls, 9.5)

    5.区域的连通域分析

    筛选出更类似矩形的区域

    1. connection (Balls, SingleBalls)
    2. select_shape_std (SingleBalls, Rect, 'rectangle1', 90)

    6.将类似于矩形的区域排除

        difference (SingleBalls, Rect, IntermediateBalls)

    7.根据图像上的像素,对区域进行展开

    1. gen_empty_region (Forbidden)
    2. expand_gray (IntermediateBalls, Bond, Forbidden, RegionExpand, 4, 'image', 6)

    8.继续进行开运算

        opening_circle (RegionExpand, RoundBalls, 15.5)

    完成目标。

    4.文件

    1. * ball_seq.hdev: Inspection of Ball Bonding
    2. *
    3. dev_update_off ()
    4. ImageNames := 'die/' + ['die_02','die_03','die_04','die_07']
    5. dev_set_colored (12)
    6. read_image (Bond, ImageNames[0])
    7. get_image_size (Bond, Width, Height)
    8. dev_close_window ()
    9. dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
    10. set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
    11. dev_set_draw ('margin')
    12. dev_set_line_width (3)
    13. NumImages := |ImageNames|
    14. for I := 0 to NumImages - 1 by 1
    15. read_image (Bond, ImageNames[I])
    16. dev_display (Bond)
    17. min_max_gray (Bond, Bond, 0, Min, Max, Range)
    18. threshold (Bond, Bright, Max - 80, 255)
    19. shape_trans (Bright, Die, 'rectangle2')
    20. dev_display (Die)
    21. reduce_domain (Bond, Die, DieGrey)
    22. min_max_gray (Die, Bond, 0, Min, Max, Range)
    23. threshold (DieGrey, Wires, 0, Min + 30)
    24. fill_up_shape (Wires, WiresFilled, 'area', 1, 100)
    25. opening_circle (WiresFilled, Balls, 9.5)
    26. connection (Balls, SingleBalls)
    27. select_shape_std (SingleBalls, Rect, 'rectangle1', 90)
    28. difference (SingleBalls, Rect, IntermediateBalls)
    29. gen_empty_region (Forbidden)
    30. expand_gray (IntermediateBalls, Bond, Forbidden, RegionExpand, 4, 'image', 6)
    31. opening_circle (RegionExpand, RoundBalls, 15.5)
    32. sort_region (RoundBalls, FinalBalls, 'first_point', 'true', 'column')
    33. smallest_circle (FinalBalls, Row, Column, Radius)
    34. NumBalls := |Radius|
    35. Diameter := 2 * Radius
    36. meanDiameter := sum(Diameter) / NumBalls
    37. mimDiameter := min(Diameter)
    38. dev_display (RoundBalls)
    39. if (I != NumImages)
    40. disp_continue_message (WindowHandle, 'black', 'true')
    41. endif
    42. stop ()
    43. endfor

  • 相关阅读:
    winlicense官方版是一款功能专业强大的编程软件
    学习记录十六 ---- spring boot
    ffmpeg推流+nginx转发+拉流(RTMP拉流)
    优秀的程序员不是你的尽头,而是起点
    【Xilinx】Zynq\MPSoc\Versal不同速度等级下的ARM主频
    PLC-Recorder访问能力测试报告(4560变量测试)
    自动控制原理3.5---线性系统的稳定性分析
    【openGauss】一种可能是目前最快的从ORACLE同步数据到MogDB(openGauss)的方式
    LeetCode_279_完全平方数
    基础生态学终结版复习题
  • 原文地址:https://blog.csdn.net/linux_huangyu/article/details/139530953