项目需求:
此项目halcon检测半导体行业引脚有无粘连,并显示。
素材如下:
检测后的效果如下:
Halcon代码如下:
read_image (Image, '扩视_8')
gen_rectangle1 (ROI_0, 14.9286, -0.149507, 108.871, 637.748)
reduce_domain (Image, ROI_0, ImageReduced)
threshold (ImageReduced, Region, 0, 128)
opening_rectangle1 (Region, RegionOpening, 18, 18)
connection (RegionOpening, ConnectedRegions)
sort_region (ConnectedRegions, SortedRegions, 'first_point', 'true', 'column')
* Image Acquisition 01: Do something
count_obj (SortedRegions, Number)
for Index1 := 1 to Number-1 by 1
select_obj (SortedRegions, ObjectSelected1, Index1)
smallest_rectangle2 (ObjectSelected1, Row100, Column100, Phi, Length1, Length2)
********取边缘
boundary (ObjectSelected1, RegionBorder, 'inner')
********生成线
gen_region_line (RegionLines, Row100, Column100, Row100-50, Column100)
********取交集
intersection (RegionBorder, RegionLines, RegionIntersectionOUT1)
select_obj (SortedRegions, ObjectSelected2, Index1+1)
smallest_rectangle2 (ObjectSelected2, Row101, Column101, Phi1, Length21, Length22)
boundary (ObjectSelected2, RegionBorder1, 'inner')
gen_region_line (RegionLines1, Row101, Column101, Row101-50, Column101)
intersection (RegionBorder1, RegionLines1, RegionIntersectionOUT2)
distance_rr_min (RegionIntersectionOUT1, RegionIntersectionOUT2, MinDistance, Row1, Column1, Row2, Column2)
disp_message (200000,Index1+'尺寸:'+ MinDistance, 'Image', Row1, Column1, 'black', 'true')
wait_seconds (0.2)
endfor