其他分享
首页 > 其他分享> > 2021-07-28

2021-07-28

作者:互联网

不规则图形中拟合提取圆

通过对内外圆的不同操作进行圆的拟合操作
代码如下

dev_close_window()
read_image(Image, 'Pic/Images/1.bmp')
dev_open_window(0, 0, 512, 512, 'black', WindowHandle)
dev_display(Image)
mean_image(Image, ImageMean, 3, 3)
gen_rectangle1 (ROI_0, 541.445, 913.281, 1352.2, 1875.16)
reduce_domain(Image, ROI_0, RoiImage)

threshold (Image, SurfaceRegion, 126, 255)
connection(SurfaceRegion, SurfaceConnectedRegions)
select_shape( SurfaceConnectedRegions, SurfaceSelectedRegions, 'area', 'and', 901001, 1000000)
gen_contour_region_xld(SurfaceSelectedRegions, SurfaceContours, 'border')

segment_contours_xld(SurfaceContours, OutConSplit, 'lines_circles', 5, 4, 2)
select_contours_xld(OutConSplit, OutSeCon, 'contour_length', 600, 1000, -0.5, 0.5)
fit_circle_contour_xld(OutSeCon, 'algebraic', -1, 0, 0, 3, 2, Row2, Column2, Radius1, StartPhi1, EndPhi1, PointOrder1)
gen_circle_contour_xld(OutContCircle, Row2, Column2, Radius1, rad(0), rad(360), 'positive', 1)
LargeRadius := [Radius1[0]+Radius1[1]+Radius1[2]+Radius1[3]+Radius1[4]]/5

mean_sp(ImageMean, ImageSPMean, 3, 3, 1, 254)

threshold (RoiImage, ThresRegions, 64, 255)
connection(ThresRegions, ThresConnectedRegions)
select_shape(ThresConnectedRegions, ThresSelectedRegions, 'area', 'and', 150000, 250000)
fill_up(ThresSelectedRegions, RegionFillUp)

gen_contour_region_xld(RegionFillUp, FillContours, 'border_holes')
segment_contours_xld(FillContours, InConSplit, 'lines_circles', 5, 4, 2)
select_contours_xld(InConSplit, InSeCon, 'contour_length', 272, 10000, -0.5, 0.5)
union_cocircular_contours_xld(InSeCon, InUnionCon, rad(360), rad(360), rad(360), 30, 30, 30, 'true', 1)
fit_circle_contour_xld(InUnionCon, 'algebraic', -1, 0, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)

gen_circle_contour_xld(ContCircle, Row, Column, Radius, rad(0), rad(360), 'positive', 1)
dev_clear_window()
**********
dev_set_color('red')
dev_display(OutContCircle)
**********

附上原图:
在这里插入图片描述
运行结果图:
在这里插入图片描述

标签:Radius1,rad,07,xld,28,dev,2021,contour,contours
来源: https://blog.csdn.net/Lonewolf_/article/details/119188510