Halcon齿轮测量

Halcon齿轮测量(Halcon学习笔记)
齿轮灰度图像如下:

Halcon齿轮测量设计流程
Halcon齿轮测量_第1张图片
首先进行阈值分割并利用面积特征选取出齿轮部分:
Halcon齿轮测量_第2张图片
创建圆的XLD轮廓:
Halcon齿轮测量_第3张图片
进行尺寸测量:
Halcon齿轮测量_第4张图片
生成测量结果并显示:
Halcon齿轮测量_第5张图片
Halcon代码如下:

* Image Acquisition 01: Code generated by Image Acquisition 01
read_image (Image, 'D:/机器视觉学习资料/Halcon学习/案例/齿轮测量/齿轮测量 - 副本/齿轮测量 - 副本/2hao20150107190909.bmp')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
threshold (Image, Regions, 25, 78)
connection (Regions, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 73394.9, 74659.5)
*draw_circle_mod 生成用户在窗口中交互创建圆的参数
draw_circle_mod (WindowHandle, Height/2, Width/2, Width/20, Row, Column, Radius)
*gen_circle_contour_xld创建圆或圆弧的XLD轮廓
gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, 6.28318, 'positive', 1)
dev_display (ContCircle)
dev_set_color ('green')
*创建计量模型的算子
create_metrology_model (MetrologyHandle)
*将计量对象添加到计量模型中
add_metrology_object_generic (MetrologyHandle, 'circle', [Row,Column,Radius], 20, 5, 1, 30, [], [], Index)
*测量,第一个参数输入的图像,第二个参数输入的句柄
apply_metrology_model (Image, MetrologyHandle)
*取得结果
get_metrology_object_result (MetrologyHandle, 0, 'all', 'result_type', 'all_param', Parameter)
*显示圆轮廓的测量范围
get_metrology_object_result_contour (Contour, MetrologyHandle, 'all', 'all', 1.5)
*显示圆的边缘轮廓
get_metrology_object_measures (Contours, MetrologyHandle, 'all', 'all', Row1, Column1)
dev_display (Contours)
stop()
*清空计量模型
clear_metrology_model (MetrologyHandle)
dev_display (Image)
dev_display (Contours)
message1:='CenterRow'+Parameter[0]
message2:='CenterCol'+Parameter[1]
message3:='Radious'+Parameter[2]
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
disp_message (WindowHandle, message1, 'window', 0, -1, 'forest green', 'false')
disp_message (WindowHandle, message2, 'window', 20, -1, 'forest green', 'false')
disp_message (WindowHandle, message3, 'window', 40, -1, 'forest green', 'false')

你可能感兴趣的:(Halcon,机器视觉,视觉检测,图像处理,计算机视觉)