Halcon学习---案例实战(15)--断裂点提取

inspect_solar_fingers.hdev

代码比较简单,主要谈思想:

目标:要求取中间白线的断裂点,有断裂点则NG并标出位置,否则OK;

1.通过低阈值提取到除白线以外的所有背景区域,然后打散。(如果存在断裂点,有些区域会比相对应的区域大)

2.通过面积和宽高限制将区域进行分开讨论(这个限制条件一般是正常范围内的区域,如果存在断裂点,会超过限制,区域会被舍弃)

3.利用第一步结果差分第二步结果,断裂点所在区域会被提取到

4.再用特定宽高进行腐蚀,能定位到断裂点的具体位置

* For the solar industry, a common problem is the damage of
* fingers of solar cells. This example shows how to
* extract the broken fingers using morphology.
* 
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)
* 
* 
* For each image of a solar cell, extract defect areas
NumImages := 6
for Index := 1 to NumImages by 1
    read_image (Image, ImageName + Index$'02')
    decompose3 (Image, ImageR, ImageG, ImageB)
    * Segment dark regions (everything except the fingers)
    threshold (ImageR, Region, 0, 159)
    connection (Region, ConnectedRegions)
    * Select good parts and clutter regions
    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])
    * Regions that are neither good parts nor clutter contain broken fingers
    difference (ConnectedRegions, GoodSmallParts, Difference)
    difference (Difference, GoodLongParts, Difference)
    difference (Difference, Clutter, BrokenParts)
    shape_trans (BrokenParts, BrokenPartsTrans, 'rectangle1')
    * Isolate the break for visualization
    erosion_rectangle1 (BrokenParts, RegionErosion, 1, 25)
    connection (RegionErosion, ConnectedBreaks)
    shape_trans (ConnectedBreaks, Breaks, 'outer_circle')
    dilation_circle (Breaks, Breaks, 6)
    * Remove empty regions
    * (This could also be achieved with set_system('store_empty_region','false')
    select_shape (Breaks, Breaks, 'area', 'and', 1, 99999999)
    count_obj (Breaks, CountBreaks)
    * 
    *  Display results of inspection
    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 only one defect is present, zoom in
    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

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

枫呱呱

如果这篇博文对你有用,求打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值