//获取图片
read_image (Image18, 'D:/tu/18.bmp')
//二值化
threshold (Image18, Region1, 28, 255)
//膨胀腐蚀操作
erosion_rectangle1 (Region1, ccc, 80, 80)
dilation_rectangle1 (ccc, aaa,80, 80)
//像素融合
connection (aaa, ConnectedRegions)
//获取边缘
gen_contour_region_xld (ConnectedRegions, Contours, 'border')
//选择合适大小区域
select_shape_xld (Contours, SelectedXLD, 'area', 'and', 999999, 9999999)
//选择圆
select_shape(ConnectedRegions, SelectedRegions1, 'circularity', 'and', 0.6, 1)
//感觉有点大,腐蚀一下
erosion_rectangle1 (SelectedRegions1, SelectedRegions1, 40, 40)
//获取取到圆的边缘
gen_contour_region_xld (SelectedRegions1, ppp, 'border')
//获取圆面积以及中心坐标
area_center (SelectedRegions1, Area, Row,Column)
//获取包围圈长度
fuzzy_perimeter (SelectedRegions1,Image18, 0, 255, Perimeter)
//求半径
CRadius:=sqrt(Area/3.1415926)
//求周长
CCircumference := CRadius*2*3.1415926
//显示图片
dev_display(Image18)
dev_display(ppp)
//改变字体颜色
dev_set_color ('red')
//显示圆心
disp_circle (3600, Row, Column, 32)
//显示文字
set_tposition (3600, Row+150, Column+50)
write_string (3600,'半径为'+CRadius)
read_image (Image18, 'D:/tu/18.bmp')
threshold (Image18, Region1, 220, 255)
erosion_rectangle1 (Region1, ccc, 20, 20)
dilation_rectangle1 (ccc, aaa,20, 20)
connection (aaa, ConnectedRegions)
gen_contour_region_xld (ConnectedRegions, Contours, 'border')
select_shape(ConnectedRegions, SelectedRegions1, 'circularity', 'and', 0.6, 1)
gen_contour_region_xld (SelectedRegions1, ppp, 'border')
area_center (SelectedRegions1, Area, Row,Column)
fuzzy_perimeter (SelectedRegions1,Image18, 0, 255, Perimeter)
CRadius:=sqrt(Area/3.1415926)
CCircumference := CRadius*2*3.1415926
dev_display(Image18)
dev_display(ppp)
dev_set_color ('red')
disp_circle (3600, Row, Column, 32)
set_tposition (3600, Row+250, Column-500)
write_string (3600,'圆心为:('+Column+','+Row+')')
set_tposition (3600, Row+150, Column-500)
write_string (3600,'半径为: '+CRadius)
效果更加准确
选取面积可以放在选圆下面,使选择的圆更加准确