当前位置:网站首页>Halcon knowledge: segment_ contours_ XLD operator

Halcon knowledge: segment_ contours_ XLD operator

2022-07-07 01:57:00 Mr anhydrous

One 、 Case description

         Boundary extraction : Previous edge extraction was based on foreground passing thresold Extract the region , Then propose from the area XLD, however , If the area cannot be raised, it will be difficult to do . This example tells you , There is no need for binary extraction , You can also take out the edge ,edges_sub_pix It can be done .

         This case mainly presents a kind of diagram with unclear contrast , Extract the circle 、 The ellipse 、 Examples of straight lines .     

In use Halcon In the process of image processing , The contour must be segmented , Divide the contour into straight segments 、 round ( Or arc )、 Different segments of elliptical arc , The most commonly used operator for contour segmentation is segment_contours_xld.

Two 、 Operator introduction

segment_contours_xld——Segment XLD contours into line segments and circular or elliptic arcs( Will a XLD The contour is divided into straight line segments 、 round ( arc )、 Elliptical arc .)

signature( grammar ):
Parameter description :
Contours The contour that needs to be segmented .
ContoursSplit The contour after segmentation tuple.
Mode How to segment the contour , You can choose 'lines'( Use straight line segment segmentation ), 'lines_circles'( Use line segments and circles ( arc ) Division ), 'lines_ellipses'( Use line segments and elliptical arcs to segment ).
SmoothCont Parameters of contour smoothing , It can suppress too short line segments in the process of polyline approximation , It can approach circles and ellipses more robustly .
MaxLineDist1 For the first time to use Ramer Algorithm ( That is, use straight line segments to approach the contour step by step ) At the time of the MaxLineDist, After approaching completion , Then use arc or elliptical arc to fit the adjacent segment , If the distance from the fitting arc to the contour is less than the distance from the approximation line segment to the contour , Replace the approximation line segment with an arc , This process iterates uniformly until all line segments are fitted .
MaxLineDist2 When approaching the contour for the second time MaxLineDist, Only when MaxLineDist2
This two-step approximation algorithm is more efficient , Because in the first approximation , There are few straight-line segments of progressive approximation , Therefore, the arc with larger diameter can be segmented efficiently . In the second approximation , The contour that can be approximated by a small diameter arc is found , At the same time, the end of the large diameter arc is redefined .
Remark:
The contour obtained by segmentation is a straight line segment 、 round ( arc ) Or the elliptical arc can pass the global attribute of the segmented contour 'cont_approx’ Parameter value ( Reference resources get_contour_global_attrib_xld).
If 'cont_approx'=-1, This part of the contour is most suitable to be fitted as a straight line segment .
If 'cont_approx'=0, This part of the contour is most suitable to be fitted as an elliptical arc .
If 'cont_approx'=1, This part of the contour is most suitable to be fitted as an arc .

3、 ... and 、 Examples of contour segmentation :

read_image (Image, 'pumpe')
edges_sub_pix (Image, Edges, 'canny', 1.5, 15, 40)
segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 4, 2)
count_obj (ContoursSplit, Number)
gen_empty_obj (Lines)
gen_empty_obj (Circles)

for I := 1 to Number by 1
    select_obj(ContoursSplit, Contour, I)
    get_contour_global_attrib_xld (Contour, 'cont_approx', Type)
    if (Type == -1)
        concat_obj (Lines, Contour, Lines)
    else
        concat_obj (Circles, Contour, Circles)
    endif
endfor

fit_line_contour_xld (Lines, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
fit_circle_contour_xld (Circles, 'atukey', -1, 2, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)

原网站

版权声明
本文为[Mr anhydrous]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130909483961.html