【C#】halcon案例-圓測(cè)量
|
admin
2023年2月27日 11:23
本文熱度 499
|
一.要求:
如下圖,識(shí)別左邊大的圓孔:
read_image (Image, 'E:01.JPG')get_image_size (Image, Width, Height)dev_open_window (0, 0, Width/2, Height/2, 'black', WindowHandle)rgb1_to_gray (Image, GrayImage)gen_circle (ROI_0, 541.5, 141.5, 151.539)reduce_domain (GrayImage, ROI_0, ImageReduced)threshold (ImageReduced, Regions, 115, 255)boundary (Regions, RegionBorder, 'inner')dilation_circle (RegionBorder, RegionDilation, 2.5)*在弧形區(qū)域進(jìn)行邊緣檢測(cè)edges_sub_pix (ImageReduced, Edges, 'canny', 1, 20, 40)*對(duì)檢測(cè)的邊緣進(jìn)行分割,識(shí)別線或者圓'lines_circles',segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 5, 8)*統(tǒng)計(jì)識(shí)別出圓或線的數(shù)量count_obj (ContoursSplit, Number)dev_open_window (0, 0, Width/2, Height/2, 'black', WindowHandle)dev_update_window ('off')*儲(chǔ)存擬合圓的圓心坐標(biāo)和半徑for i := 1 to Number by 1 *選擇輪廓并根據(jù)特性確定是否擬合圓:* Attrib = -1 線段 0 橢圓 1圓 select_obj (ContoursSplit, Objectselected, i) get_contour_global_attrib_xld (Objectselected, 'cont_approx', Attrib) fit_circle_contour_xld (Objectselected, 'ahuber', -1, 2, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder) *這里會(huì)生成大量的擬合圓,通過(guò)添加條件,選取自己需要的圓,這里 *條件為半徑,(可以自己注釋條件,查看所有擬合圓結(jié)果 ) if(Radius<73 and Radius>70) gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, rad(360), 'positive', 1.0)
該文章在 2023/2/27 11:24:19 編輯過(guò)
|
|