# 求圆环毛刺凸出高度是否超标的算法实现

 1 read_image (Image, 'C:/Users/02/Desktop/Ring.png')
2 dev_set_draw ('margin')
3 threshold (Image, Region, 0, 253)
4 fill_up_shape (Region, RegionFillUp, 'area', 1, 20000)
5 fill_up (RegionFillUp, RegionFillUp1)
6 difference (RegionFillUp1, RegionFillUp, CircleInner)
7 smallest_circle (CircleInner, Row, Column, Radius)
8 find_circle (Image, PartCircleXLD, Regions, Cross, Circle, Row, Column, Radius + 100, 0, 360, 40, 100, 20, 1, 40, 'negative', 'first', 'inner', 10, 'circle', RowCenter, ColCenter, Radius1)
9 gen_region_contour_xld (Circle, RegionCircle, 'filled')
10
11 *稍微膨胀一下，便于后续处理
12 dilation_circle (RegionCircle, RegionCircle, 1.5)
13 difference (RegionFillUp, RegionCircle,RegionDifference)
14 opening_circle (RegionDifference, RegionDifference, 3.5)
15 connection (RegionDifference, ConnectedRegions)
16 select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 50, 9999999)
17 count_obj (SelectedRegions, Number)
18
19 *后面精确测量一下多出的毛刺是否超标
20 gen_empty_obj (RegionDefects)
21 if (Number >0)
22     for i := 1 to Number by 1
23         select_obj (SelectedRegions, ObjectSelected, i)
24         distance_pr (ObjectSelected, RowCenter, ColCenter, DistanceMin, DistanceMax)
25         *如果毛刺凸出高度超过20像素，则判断超标
26         if (DistanceMax - Radius1 > 20)
27             concat_obj (RegionDefects, ObjectSelected, RegionDefects)
28         endif
29     endfor
30 endif
31
32 dev_display (Image)
33 dev_display (RegionDefects)
34 disp_cross (3600, RowCenter, ColCenter, 20, 0.45)

https://files.cnblogs.com/files/xh6300/find_line_find_circle.zip

posted on 2019-08-01 11:40  xh6300  阅读(2046)  评论(8编辑  收藏  举报