★add_metrology_object_generic
(MetrologyHandle, Shape, ShapeParam, MeasureLength1, MeasureLength2, MeasureSigma, MeasureThreshold, GenParamName, GenParamValue : Index)
①MetrologyHandle参数:指的Metrology模型的数据结构句柄。可以理解为Create的时候声明的数据地址;
②Shape参数:指定加入的模型。line(直线),circle(圆),rectangle2(任意角度矩形)和ellipse(椭③ShapeParam参数:模型参数。直线[RowBegin, ColumnBegin, RowEnd, ColumnEnd];圆[row,column,radius];矩形[Row, Column, Phi, Length1, Length2];椭圆[Row, Column, Phi, Radius1, Radius2]。
④MeasureLength1参数:Measure Rectangle 垂直于切线的半轴的长度。这个不理解的话建议看懂1D测算的Measure原理。
⑤MeasureLength2参数:Measure Rectangle 平行于切线的半轴的长度。这个不理解的话建议看懂1D测算的Measure原理。
⑥MeasureSigma参数:高斯滤波函数的σ。
⑦MeasureThreshold参数:边缘的Gray值最小振幅。
⑧GenParamName,GenParamValue参数:通常情况下为空就好。
⑨Index参数:这个参数是一个索引值。等于是给他个查询号,后面需要专门对这个模型设置参数或者获取结果的时候会用到。
*创建NCC模板匹配
gen_rectangle1 (ROI, 1150, 3330, 1320, 3550)
reduce_domain (test_pic, ROI, ImageReduced)
area_center (ROI, Area, model_Row, model_Column)
create_ncc_model (ImageReduced, 'auto', -rad(15), rad(15), 'auto', 'use_polarity', ModelID)
*模板匹配
count_seconds (Seconds1)
find_ncc_model (ImageReduced1, ModelID, -rad(15), rad(15), 0.8, 1, 0.5, 'true', 0, Row, Column, Angle, Score)
count_seconds (Seconds2)
dev_display_ncc_matching_results (ModelID, 'green', Row, Column, Angle, 0)
*卡尺找圆
Row:=1207
Column:=3456
Radius:=40
circle:=[Row,Column,Radius]
*创建句柄
create_metrology_model(MetrologyHandle_circle)
*添加圆模型
add_metrology_object_generic (MetrologyHandle_circle, 'circle', [circle], 15,3, 1, 60, [], [], Index)
*设置测量对象的参数,根据需要限定参数
set_metrology_object_param (MetrologyHandle_circle,'all','measure_transition','negative')
set_metrology_object_param (MetrologyHandle_circle, 'all', 'num_measures', 30)
*开始找边缘,顺便把边缘上卡尺找到的所有点坐标输出在ROW,Column里面(数组形式)
apply_metrology_model (test_pic, MetrologyHandle_circle)
get_metrology_object_measures (Contours, MetrologyHandle_circle, 'all', 'all', Row1, Column1)
gen_cross_contour_xld (Cross_circle, Row1, Column1, 8, Angle)
gen_contour_polygon_xld (Contour, Row1, Column1)
*找出圆心坐标
fit_circle_contour_xld (Contour, 'algebraic', -1, 0, 0, 3, 2, Row2, Column2, Radius, StartPhi, EndPhi, PointOrder)
gen_circle_contour_xld (ContCircle, Row2, Column2, Radius, rad(0), rad(360), 'positive', 1)
Parameter_ciecle:=[Row2, Column2]
*卡尺找线
shapeParam_line1:=[250,2050,500,2050]
shapeParam_line2:=[666,2200,666,2450]
*创建句柄
get_image_size (test_pic, Width, Height)
create_metrology_model (MetrologyHandle_line1)
create_metrology_model (MetrologyHandle_line2)
set_metrology_model_image_size (MetrologyHandle_line1, Width, Height)
set_metrology_model_image_size (MetrologyHandle_line2, Width, Height)
* 添加线模型
add_metrology_object_generic (MetrologyHandle_line1, 'line', shapeParam_line1, 30, 5, 1, 30, [], [], Index1)
add_metrology_object_generic (MetrologyHandle_line2, 'line', shapeParam_line2, 30, 5, 1, 30, [], [], Index2)
*设置测量对象的参数,根据需要限定参数
set_metrology_object_param (MetrologyHandle_line1, 'all', 'measure_transition', 'positive')
set_metrology_object_param (MetrologyHandle_line1, 'all', 'num_measures',20)
set_metrology_object_param (MetrologyHandle_line2, 'all', 'measure_transition', 'positive')
set_metrology_object_param (MetrologyHandle_line2, 'all', 'num_measures',20)
* set_metrology_object_param (MetrologyHandle_line1, 'all', 'num_instances', 40)
* set_metrology_object_param (MetrologyHandle_line1, 'all', 'measure_sigma', 1)
* set_metrology_object_param (MetrologyHandle_line1, 'all', 'measure_length1', 80)
* set_metrology_object_param (MetrologyHandle_line1, 'all', 'measure_length2', 1)
* set_metrology_object_param (MetrologyHandle_line1, 'all', 'measure_threshold',50)
* set_metrology_object_param (MetrologyHandle_line1, 'all', 'measure_interpolation', 'bicubic')
* set_metrology_object_param (MetrologyHandle_line1, 'all', 'measure_select', 'all')
* set_metrology_object_param (MetrologyHandle_line1, 'all', 'min_score', 0.7)
*开始找边缘,顺便把边缘上卡尺找到的所有点坐标输出在ROW,Column里面(数组形式)
apply_metrology_model (test_pic, MetrologyHandle_line1)
get_metrology_object_measures (Contours1, MetrologyHandle_line1, 'all', 'all', Row3, Column3)
apply_metrology_model (test_pic, MetrologyHandle_line2)
get_metrology_object_measures (Contours2, MetrologyHandle_line2, 'all', 'all', Row4, Column4)
*把点显示出来
gen_cross_contour_xld (Cross_line1, Row3, Column3, 30,rad(45))
gen_cross_contour_xld (Cross_line2, Row4, Column4, 30,rad(45))
*得到线的起点和终点坐标并显示出来
get_metrology_object_result (MetrologyHandle_line1, 'all', 'all', 'result_type', 'all_param', Parameter_line1)
get_metrology_object_result_contour (Contour1, MetrologyHandle_line1, 'all', 'all', 1.5)
get_metrology_object_result (MetrologyHandle_line2, 'all', 'all', 'result_type', 'all_param', Parameter_line2)
get_metrology_object_result_contour (Contour2, MetrologyHandle_line2, 'all', 'all', 1.5)