代码中关键知识:
1、循环读取图片
2、基本图像处理:开运算、二值化、内部填充、
3、获取图像边缘线,分割曲线,然后计算曲线的circularity_xld圆率范围,和area_center_xld的面积大小,做阈值筛选
4、然后fit_circle_contour_xld 拟合,确定圆形的半径大小,然后对半径进行阈值筛选
图片数据下载:https://download.csdn.net/download/zzx2016zzx/88809987
dev_close_window()
dev_clear_window()
dev_open_window (0, 0, 646, 492, 'black', WindowHandle)
list_image_files ('/image', 'default', [], ImageFiles)
for Index := 0 to |ImageFiles|-1 by 1read_image (Image, ImageFiles[Index])get_image_size (Image, Width, Height)count_channels (Image, Channels)if(Channels==3)rgb1_to_gray (Image, GrayImage)elsecopy_image (Image, GrayImage)endifthreshold (GrayImage, Regions, 119, 255)connection (Regions, ConnectedRegions)fill_up (ConnectedRegions, RegionFillUp)select_shape (RegionFillUp, SelectedRegions, ['area','circularity'], 'and', [4000,0.24], [23000,1])opening_circle (SelectedRegions, RegionOpening, 3.5)gen_contour_region_xld (RegionOpening, Contours, 'border')segment_contours_xld (Contours, ContoursSplit, 'lines_circles', 10, 4, 10)count_obj (ContoursSplit, Number)for i:=1 to Number by 1select_obj (ContoursSplit, ObjectSelected, i)area_center_xld (ObjectSelected, Area, Row, Column, PointOrder)circularity_xld (ObjectSelected, Circularity)if(Area>3400 and Circularity>0.22)fit_circle_contour_xld (ObjectSelected, 'algebraic', -1, 0, 0, 3, 2, Row1, Column1, Radius, StartPhi, EndPhi, PointOrder1)if(Radius>80)gen_circle (Circle, Row1, Column1, Radius)dev_display (Image)dev_display(Circle) breakendifendifendforstop()
endfor
效果图: