read_image (Image, ‘rings_and_nuts’)
*阈值筛选
threshold (Image, Region, 0, 128)
*获取轮廓
*1.边缘提取轮廓 亚像素
edges_sub_pix (Image, Edges, ‘canny’, 1, 20, 40)
*像素提取轮廓
edges_image (Image, ImaAmp, ImaDir, ‘canny’, 1, ‘nms’, 20, 40)
*region——>轮廓 'border’像素边界 ‘center’ 像素中心 (外轮廓)
gen_contour_region_xld (Region, Contours, ‘center’)
*筛选圆弧度
circularity_xld (Edges, Circularity)
*数组操作 筛选圆弧度大于0.7的 为1 小于则为0
tuple_greater_elem (Circularity, 0.9, Greater)
*数组操作 返回数组元素为1的元素下标
tuple_find (Greater, 1, Indices)
dev_set_color (‘green’)
*选择大于0.9的圆
select_obj (Edges, ObjectSelected, Indices+1)
*拟合圆 输入轮廓
fit_circle_contour_xld (ObjectSelected, ‘algebraic’, -1, 0, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
*显示拟合的五个圆
gen_circle_contour_xld (OutCircle, Row, Column, Radius, StartPhi, EndPhi, ‘positive’, 1)
*点拟合轮廓
*选择第一个齿轮轮廓
select_obj (Contours, ObjectSelected1, 2)
*得到轮廓的行列点(部分点前300个)
get_contour_xld (ObjectSelected1, Row1, Column1)
tuple_select_range (Row1, 0, 300, SelectedRow)
tuple_select_range (Column1, 0, 300, SelectedCol)
*用这些点做轮廓
gen_contour_polygon_xld (ObjectSelected1, SelectedRow, SelectedCol)
*拟合
fit_circle_contour_xld (ObjectSelected1, ‘algebraic’, -1, 0, 0, 3, 2, Row2, Column1, Radius1, StartPhi1, EndPhi1, PointOrder1)
*作圆
gen_circle_contour_xld (ContCircle1, Row2, Column1, Radius1, StartPhi1, EndPhi1, ‘negative’, 1)
*轮廓分割
segment_contours_xld (ObjectSelected1, ContoursSplit, ‘lines_circles’, 1, 1, 1)
*轮廓裁剪(类似 补)
clip_contours_xld (ContCircle1, ObjectSelected1, Row2, Column1, Row2, Column1)