- * 识别区域
- *scale_image(Image,Invert,minGray,maxGray)
- gen_rectangle1 (Rectangle, startY, startX, endY, endX)
- reduce_domain (Image, Rectangle, ImageReduced)
- * 初步边缘提取
- edges_image (ImageReduced, ImaAmp, ImaDir, 'lanser2', 0.9, 'nms', 8, 16)
- threshold (ImaAmp, Region1, 1, 255)
- connection (Region1, ConnectedRegions)
- select_shape (ConnectedRegions, SelectedRegions, ['outer_radius','anisometry','area'], 'and', [10,1,50], [30,3.9,300])
- shape_trans (SelectedRegions, RegionTrans, 'outer_circle')
- dilation_circle (RegionTrans, RegionDilation,5.5)
- union1 (RegionDilation, RegionUnion)
- reduce_domain (Image, RegionUnion, ImageReduced2)
- * 详细边缘提取
- edges_sub_pix (ImageReduced2, Edges, 'lanser2', 0.1, 8, 16)
- select_shape_xld (Edges, SelectedXLD, ['contlength','outer_radius','circularity'], 'and', [40,10,0.5], [99999,99999,1])
- *segment_contours_xld (SelectedXLD, ContoursSplit, 'lines_circles', 4, 2, 2)
- gen_region_contour_xld(SelectedXLD, SelectedRegion_ContoursSplit,'filled')
- union1 (SelectedRegion_ContoursSplit, RegionUnion_new)
- reduce_domain( Image,RegionUnion_new, ImageReduced_RegionUnion_new)
- threshold(ImageReduced_RegionUnion_new, Region2, 1, 255)
- connection (Region2, ConnectedRegions2)
- * 筛选
- count_obj (ConnectedRegions2, NumberContours)
- *gen_empty_obj (Circles)
- for i := 1 to NumberContours by 1
- select_obj (ConnectedRegions2, ObjectSelected, i)
- gen_region_contour_xld(ObjectSelected, Object123, 'filled')
- *dev_display (ObjectSelected)
- reduce_domain(Image, Object123, Image_Object_Reduced)
- *get_contour_global_attrib_xld (ObjectSelected, 'cont_approx', Attrib)
- *if (Attrib == 1)
- * concat_obj (Circles, ObjectSelected, Circles)
- *endif
- endfor
复制代码
现在能够把钉子和类似钉子的圆形取出来,而且可以循环检查,但是gen_region_contour_xld(ObjectSelected, Object123, 'filled')和 reduce_domain(Image, Object123, Image_Object_Reduced)因为ObjectSelected不是region所以不行 |