原图
源码
read_image ( Image , '0.bmp' )
dev_clear_window ( )
dev_open_window_fit_image ( Image , 0 , 0 , - 1 , - 1 , WindowHandle )
dev_display ( Image ) binary_threshold ( Image , Region , 'max_separability' , 'dark' , UsedThreshold )
connection ( Region , ConnectedRegions )
select_shape ( ConnectedRegions , SelectedRegions , 'area' , 'and' , 100 , 100000 ) gen_empty_obj ( CircleRegion )
PointNumber: = 0
while ( PointNumber < 8 ) draw_point ( WindowHandle , Row , Column ) gen_region_points ( Region1 , Row , Column ) select_shape_proto ( SelectedRegions , Region1 , SelectedRegions1 , 'overlaps_abs' , 1 , 5 ) count_obj ( SelectedRegions1 , Number ) if ( Number > 0 ) concat_obj ( CircleRegion , SelectedRegions1 , CircleRegion ) PointNumber: = PointNumber + 1 endif
endwhile smallest_circle ( CircleRegion , Row1 , Column1 , Radius ) pts_to_best_circle ( Circle , Row1 , Column1 , RowCenter , ColCenter , Radius ) dev_display ( Image ) dev_display ( Circle )
pts_to_best_circle 函数
RowCenter : = 0
ColCenter : = 0
Radius : = 0 gen_empty_obj ( Circle )
tuple_length ( Cols , Length ) if ( Length > 2 ) gen_contour_polygon_xld ( Contour , Rows , Cols ) fit_circle_contour_xld ( Contour , 'geotukey' , - 1 , 0 , 0 , 3 , 2 , RowCenter , ColCenter , Radius , StartPhi , EndPhi , PointOrder ) tuple_length ( StartPhi , Length1 ) if ( Length1 < 1 ) return ( ) endif gen_circle_contour_xld ( Circle , RowCenter , ColCenter , Radius , StartPhi , EndPhi , PointOrder , 1 ) endif
return ( )
处理结果