【C#】halcon案例-圆测量
|
admin
2023年2月27日 11:23
本文热度 477
|
一.要求:
如下图,识别左边大的圆孔:
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)edges_sub_pix (ImageReduced, Edges, 'canny', 1, 20, 40)*对检测的边缘进行分割,识别线或者圆'lines_circles',segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 5, 8)count_obj (ContoursSplit, Number)dev_open_window (0, 0, Width/2, Height/2, 'black', WindowHandle)dev_update_window ('off')for i := 1 to Number by 1 *选择轮廓并根据特性确定是否拟合圆:* 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) *这里会生成大量的拟合圆,通过添加条件,选取自己需要的圆,这里 *条件为半径,(可以自己注释条件,查看所有拟合圆结果 ) 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 编辑过
|
|