机器视觉halcon软件:获取圆形的半径和圆度

来源:互联网 发布:python 创建临时文件 编辑:程序博客网 时间:2024/05/24 07:11

1、要测量一个圆的直径,可以先通过阈值筛选出所需部分:threshold();

2、然后将选中部分组合connection (),选择其中类圆度高的部分(根据选中部分与圆的相似度筛选出圆型部分):select_shape ();

3、选择将所选的类圆区域扩大4个像素点作为一个区域,缩小2个像素点作为一个区域,然后将连个区域合并,再得到两个区域不同的部分,那么这个圆区域的边缘就在这个合并区域中。使用的算子有:dilation_circle,erosion_circle,difference,union1;

4、用算子edges_sub_pix ()提取其边缘轮廓;

5、此时的圆形区域并不是真正的圆,需用一个椭圆去拟合该圆对象:fit_ellipse_contour_xld;


read_image:


Image:



halcon代码:

dev_clear_window()

dev_close_window()
read_image (read_Image, 'C:/Users/Leason/Desktop/试验/2.jpg')
rgb1_to_gray (read_Image, Image)
get_image_size (Image, Width, Height)
dev_open_window_fit_image (Image, 0, 0, Width/3, Height/3, WindowHandle)
dev_display (Image)
gen_rectangle1 (ROI, 239.876, 8.5, 513.303, 695.5)
reduce_domain (Image, ROI, ImageReduced)
threshold (ImageReduced, ROI, 80, 255)
connection (ROI, DarkRegions)
select_shape (DarkRegions, Circles, ['circularity','area'], 'and', [0.85,50], [1.0,99999])
count_obj (Circles, Number)//计算圆形的数量

select_obj (Circles, PillSelected,1)

dilation_circle (Circles, ROIOuter, 4)
erosion_circle (Circles, ROIInner, 2)
difference (ROIOuter, ROIInner, ROI_dif)
union1 (ROI_dif, ROIEdges)

reduce_domain (ImageReduced, ROIEdges, ImageReduced1)

*提取其边缘轮廓

edges_sub_pix (ImageReduced1, Edges, 'lanser2', 0.3, 10, 20)
*区域的中点坐标Row, Column,与x轴的角度Phi,半长轴Ra,半短轴Rb,开始角度StartPhi,结束角度EndPhi
fit_ellipse_contour_xld (Edges, 'ftukey', -1, 2, 0, 200, 3, 2, Row, Column, Phi, Ra, Rb, StartPhi, EndPhi, PointOrder)  
原创粉丝点击