转自微信公众号:机器视觉那些事
****关注公众号>>>>: 机器视觉那些事儿 ****
****精彩继续......*****读入图片
read_image (Image, 'cicle.bmp')*计算图片大小,并以原图尺寸显示
get_image_size (Image, Width, Height)dev_close_window ()dev_open_window_fit_size (0, 0, Width, Width, -1, -1, WindowHandle)dev_display (Image)*01. 设置ROI感兴趣区域
gen_circle (ROI, 257.633, 324.833, 187.017)* gen_rectangle1 (ROI, 50, 50, 470, 470)reduce_domain (Image, ROI, ImageReduced)*02. 二值化处理,并打散连接区域,选取目标区域
threshold (ImageReduced, Regions, 23, 255)connection (Regions, ConnectedRegions)select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 57706.4, 86146.8)*03. 将目标区域进行膨胀处理
dilation_circle (SelectedRegions, RegionDilation, 10)*04. 将目标区域进行腐蚀处理
erosion_circle (SelectedRegions, RegionErosion, 4)*填充孔洞fill_up (RegionErosion, RegionFillUp)*05. 将膨胀后的区域和腐蚀后的区域进行减操作,并进行抠图处理,目的为了得到有边缘的真实图像
difference (RegionDilation, RegionFillUp, RegionDifference)union1 (RegionDifference, RegionUnion)reduce_domain (ImageReduced, RegionUnion, ImageReduced1)*06. 使用canny算子提取亚像素轮廓
edges_sub_pix (ImageReduced1, Edges, 'canny', 1, 20, 40)*07. 根据得到的真实边缘,进步处理和计算所需的线、弧、圆等
segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 4, 2)select_contours_xld (ContoursSplit, SelectedContours, 'contour_length', 8, 1000, -0.5, 0.5)union_adjacent_contours_xld (SelectedContours, UnionContours3, 10, 1, 'attr_keep')fit_circle_contour_xld (UnionContours3, 'algebraic', -1, 0, 0, 3, 2, Row1, Column1, Radius1, StartPhi, EndPhi, PointOrder)gen_circle (Circle, Row1, Column1, Radius1)*显示结果
dev_set_line_width (2)dev_set_draw ('margin')dev_display (Image)dev_display (Circle)