项目需求:
此项目halcon检测正反面,并显示。
素材如下:
*
检测后的效果如下:
*
Halcon代码如下:
read_image (Image2, '2.bmp')
rgb1_to_gray (Image2, GrayImage)
dots_image (GrayImage, DotImage, 13, 'light', 0)//2D+1
edges_color_sub_pix (DotImage, Edges, 'canny', 1, 20, 30)
select_shape_xld (Edges, SelectedXLD, 'circularity', 'and', 0.64537, 1)
select_shape_xld (SelectedXLD, SelectedXLD1, ['circularity','contlength'], 'and', [0.84352,208.8], [1,500])
fit_circle_contour_xld (SelectedXLD1, 'algebraic', -1, 0, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, 6.28318, 'positive', 1)
gen_region_contour_xld (ContCircle, Region, 'filled')
union1 (Region, RegionUnion)
reduce_domain (GrayImage, RegionUnion, ImageReduced)
threshold (ImageReduced, Region1, 0, 120)
fill_up (Region1, RegionFillUp)
dilation_circle (RegionFillUp, RegionDilation, 15.5)
connection (RegionDilation, ConnectedRegions)
shape_trans (ConnectedRegions, RegionTrans, 'inner_circle')
sort_region (RegionTrans, SortedRegions, 'character', 'true', 'row')
area_center (SortedRegions, Area, Row1, Column1)
dev_display (GrayImage)
dev_display (SortedRegions)
set_display_font (200000, 25, 'mono', 'true', 'false')
for Index := 0 to |Area|-1 by 1
if(Area[Index]>4000)
disp_message (200000, '反面', 'GrayImage', Row1[Index], Column1[Index], 'black', 'true')
else
disp_message (200000, '正面', 'GrayImage', Row1[Index], Column1[Index], 'black', 'true')
endif
endfor