*读图
read_image (Image,'C:/Users/Administrator/Desktop/检测图/孔径.bmp')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width/3, Height/3, 'black', WindowHandle)
dev_display (Image)
*转灰度
rgb1_to_gray (Image, GrayImage)
threshold (GrayImage, Regions, 0, 7)
connection (Regions, ConnectedRegions)
*选择形状,这个需要自己选择,因为每个图的大小不一样,可以根据区域和圆度选择
select_shape (ConnectedRegions, SelectedRegions, ['area','circularity'], 'and', [1099.99,0.55345], [3200,0.9346])
*开运算/腐蚀
opening_circle (SelectedRegions, RegionOpening,0.5)
dilation_circle (RegionOpening, RegionDilation, 3.5)
*数数
count_obj (RegionDilation, Number)
for i := 1 to Number by 1
*拟合圆
gen_contour_region_xld (RegionDilation, Contours1, 'border')
fit_circle_contour_xld (Contours1, 'algebraic', -1, 0, 0, 3, 2, Row1, Column1, Radius1, StartPhi, EndPhi, PointOrder)
gen_circle_contour_xld (ContCircle, Row1, Column1, Radius1, 0, 6.28318, 'positive', 1)
select_obj (ContCircle, ObjectSelected,i)
dev_display(Image)
dev_display(ObjectSelected)
*显示圆的直径
disp_message (WindowHandle, 2*Radius1[i - 1], 'image', Row1[i-1], Column1[i-1], 'forest green', 'false')
endfor