Halcon 二维测量_内外卡尺
相关算子链接:https://www.mvtec.com/doc/halcon/12/en/toc_2dmetrology.html
参考案例:
apply_metrology_model_diamond.hdev
apply_metrology_model.hdev
基本流程:
1,创建计量模型
create_metrology_model (MetrologyHandle)
2,设置计量模型的图像大小
set_metrology_model_image_size (MetrologyHandle, Width, Height)
3,将计量对象添加至计量模型中.(矩形,直线,圆,椭圆)
add_metrology_object_rectangle2_measure //矩形
add_metrology_object_circle_measure //圆或圆弧
add_metrology_object_line_measure //直线
add_metrology_object_ellipse_measure //椭圆或圆弧
4,设置计量模型参数
set_metrology_model_param
GenParamName: 'camera_param'//相机内参;'plane_pose':相机外参;'reference_system':参考位置,Value:[row, column, angle]; 'scale':缩放比例
5,设置计量对象参数
set_metrology_object_param
创建计量区域:
'measure_length1':半宽; 'measure_length2':半高
边缘检测:
'measure_sigma':高斯平滑的sigma; 'measure_threshold':最小边缘阈值 'measure_select':选择结束点'all','first','last'
'measure_transition':深色/浅色或浅色/深色边缘; 'positive'正边缘(暗/亮边缘);'negative'负边缘(亮/暗边缘);'uniform' 一致正边缘或一致负边缘,拟合时仅用一个方向的点拟合直线或圆
'measure_interpolation':插值类型; “ bicubic”双三次,“ bilinear”双线性,“ nearest_neighbor”近邻
拟合几何形状:
'min_score':最小分数 'num_instances':拟合实例最大数量
6,定位计量模型
align_metrology_model
7,测量并拟合
align_metrology_model
8,获取结果
get_metrology_object_result 获取测量对象的数据结果
get_metrology_object_result_contour 获取测量对象的结果轮廓
get_metrology_object_measures 获取计量模型的测量区域和边缘定位结果
9,删除并释放计量模型的句柄
clear_metrology_model
read_image (Diamond01, 'diamond_01.png') get_image_size (Diamond01, Width, Height) dev_set_line_width (3) *1生成计量模板 create_metrology_model (MetrologyHandle) *2设置计量模型图像大小 set_metrology_model_image_size (MetrologyHandle, Width, Height) *3添加计量几何形状 * gen_region_line (ROI_0, 153.146, 402.104, 297.938, 223.979) * gen_region_line (TMP_Region, 152.104, 398.458, 272.938, 555.75) lineRBegin:=[153,152] lineCBegin:=[402,398] lineREnd:=[297,272] lineCEnd:=[223,555] add_metrology_object_line_measure (MetrologyHandle, lineRBegin, lineCBegin, lineREnd, lineCEnd, 20, 5, 1, 30, [], [], LineIndex) *4设置计量模型参数 set_metrology_model_param (MetrologyHandle, 'reference_system', [160,400,0]) *set_metrology_object_param (MetrologyHandle, 'all', 'num_instances', 2) list_files ('E:/Halcon/Halcon练习/Week 04/day 01/diamond', ['files','follow_links'], ImageFiles) tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$','ignore_case'], ImageFiles) for Index := 0 to |ImageFiles| - 1 by 1 read_image (Image, ImageFiles[Index]) gen_rectangle1 (ROI_0, 69.8125, 173.979, 251.063, 628.146) reduce_domain (Image, ROI_0, ImageReduced) threshold (ImageReduced, Regions, 173, 255) get_region_points (Regions, Rows, Columns) *5计量模型定位 align_metrology_model (MetrologyHandle, Rows[0], Columns[0], 0) *6测量应用 apply_metrology_model (ImageReduced, MetrologyHandle) *7获得结果 get_metrology_object_result (MetrologyHandle, 'all', 'all', 'result_type', 'all_param', Parameter) get_metrology_object_result_contour (Contour, MetrologyHandle, 'all', 'all', 1.5) dev_display (Image) dev_display (Contour) stop () endfor clear_metrology_model (MetrologyHandle)