halcon 圆拟合

* Approximation of XLD contours by ellipses or elliptic arcs
* 
gen_image_const (Image, 'byte', 400, 400)
dev_set_color ('green')
gen_ellipse (Ellipse, 200, 200, rad(30), 150, 120)
paint_region (Ellipse, Image, ImageEllipse, 255, 'fill')
edges_sub_pix (ImageEllipse, EdgesComplete, 'mderiche2', 0.5, 20, 40)
* First, the easy case:
fit_ellipse_contour_xld (EdgesComplete, 'fitzgibbon', -1, 2, 0, 200, 3, 2, Row, Column, Phi, Radius1, Radius2, StartPhi, EndPhi, PointOrder)
* Now simulate a fragmented ellipse:
gen_ellipse_contour_xld (ContEllipse, Row, Column, Phi, Radius1, Radius2, StartPhi, EndPhi, PointOrder, 1.5)
gen_rectangle2 (Rectangle1, 200, 200, rad(30), 150, 2)
gen_rectangle2 (Rectangle2, 200, 200, rad(120), 150, 2)
union2 (Rectangle1, Rectangle2, Cross)
complement (Cross, CrossComplement)
reduce_domain (ImageEllipse, CrossComplement, ImageEllipseReduced)
edges_sub_pix (ImageEllipseReduced, EdgesIncomplete, 'mderiche2', 0.5, 20, 40)
* Now the difficult case:
* First, make a fit to the individual arcs.
fit_ellipse_contour_xld (EdgesIncomplete, 'fitzgibbon', -1, 2, 0, 200, 3, 2, Row, Column, Phi, Radius1, Radius2, StartPhi, EndPhi, PointOrder)
* Now we would have to determine which elliptic arcs should be merged.
* We assume that the customer is able to do this.
* If not, this could be done by clustering the elliptic arcs based on the centers
* and radii that result from the above fit.
* 
* Now we have to determine in which order the arcs should be merged.
* This can be done by sorting them according to their StartPhi.
Order := sort_index(StartPhi)
* Now construct a new contour from the coordinates of the segments to be merged:
RowsMerged := []
ColsMerged := []
for I := 0 to |Order| - 1 by 1
    select_obj (EdgesIncomplete, SelectedEdge, Order[I] + 1)
    get_contour_xld (SelectedEdge, Rows, Cols)
    if (PointOrder[Order[I]] == 'negative')
        Rows := inverse(Rows)
        Cols := inverse(Cols)
    endif
    RowsMerged := [RowsMerged,Rows]
    ColsMerged := [ColsMerged,Cols]
endfor
dev_set_color ('blue')
gen_contour_polygon_xld (Contour, RowsMerged, ColsMerged)
fit_ellipse_contour_xld (Contour, 'fitzgibbon', -1, 2, 0, 200, 3, 2, Row, Column, Phi, Radius1, Radius2, StartPhi, EndPhi, PointOrder)
dev_set_color ('red')
gen_ellipse_contour_xld (ContEllipseIncomplete, Row, Column, Phi, Radius1, Radius2, StartPhi, EndPhi, PointOrder, 1.5)

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值