*读取图片
read_image (Image, 'rings_and_nuts')
dev_get_window (WindowHandle)
dev_set_draw ('margin')
*创建模板
draw_circle (WindowHandle, modelRow, modelColumn, modelRadius)
gen_circle (Circle, modelRow, modelColumn, modelRadius)
reduce_domain (Image, Circle, ImageReduced)
create_shape_model (ImageReduced, 'auto', -0.39, 0.79, 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID)
*创建ROI
draw_circle (WindowHandle, roiRow, roiColumn, roiRadius)
*验证匹配对齐卡尺
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_translate (HomMat2DIdentity, 64, 64, HomMat2DTranslate)
rotate_image (Image, Image, 30, 'constant')
*模板搜索
find_shape_model (Image, ModelID, -0.39, 0.79, 0.5, 1, 0.5, 'least_squares', 0, 0.9, fineRow, findColumn, findAngle, Score)
get_shape_model_contours (ModelContours, ModelID, 1)
*创建测量模型
create_metrology_model (MetrologyHandle)
*设置测量对象的图像大小
get_image_size (Image, Width, Height)
set_metrology_model_image_size (MetrologyHandle, Width, Height)
*对象参数
genParamName:=['start_phi','end_phi','measure_transition','measure_select','num_measures','min_score']
genParamValue:=[rad(0),rad(360),'negative','first',10,0.4]
*创建测量ROI
add_metrology_object_circle_measure (MetrologyHandle, roiRow, roiColumn, roiRadius, 6, 2, 1, 30, genParamName, genParamValue, Index)
set_metrology_object_param (MetrologyHandle, 'all', 'num_instances', 5)
*模板匹配对齐参数
set_metrology_model_param (MetrologyHandle, 'reference_system', [modelRow, modelColumn,0])
align_metrology_model (MetrologyHandle, fineRow, findColumn, findAngle)
*应用测量
apply_metrology_model (Image, MetrologyHandle)
*获取测量结果
get_metrology_object_result (MetrologyHandle, 0, 'all', 'result_type', 'all_param', Parameter)
get_metrology_object_measures (Contours, MetrologyHandle, 'all', 'all', Row2, Column2)
get_metrology_object_result_contour (Contour, MetrologyHandle, 0, 'all', 1.5)
*清除/销毁测量对象
clear_metrology_model (MetrologyHandle)
*添加圆型测量对象到模型*
*add_metrology_object_circle_measure()*
*MetrologyHandle:测量模型句柄*
*Row:测量区域的圆心行坐标*
*Column:测量区域的圆行列坐标*
*Radius:测量区域的半径*
*MeasureLength1:垂直于边界的测量区域的一半长度*
*MeasureLength2:相切于边界的测量区域的一半长度*
*MeasureSigma:用于平滑的高斯函数的 Sigma*
*MeasureThreshold:最小边缘幅度阈值*
*GenParamName:通用参数的名称*
*GenParamValue:通用参数值*
*Index:所创建的计量对象的索引
运行结果(源码可以直接复制运行)