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