*This example shows the usage of the metrology model
* to measure circles and rectangles with subpixel
* accuracy under challenging conditions easily.**Display initializations
*停止刷新
dev_update_off ()*读取不同文件格式的图像
read_image (Image,'pads')*获取图像的大小
get_image_size (Image, Width, Height)*关闭活动图形窗口
dev_close_window ()*按指定图像的大小来打开一个窗口,默认设置
dev_open_window_fit_image (Image,0,0,-1,-1, WindowHandle)*设置显示的字体
set_display_font (WindowHandle,14,'mono','true','false')* 定义圆的大概位置和测量公差
*Define the approximate position and the measure
* tolerance for the circles
* 直接规定变量
* 行 圆的位置
RowCircle :=[52:89:500]* 圆初始化行
CircleInitRow :=[RowCircle,RowCircle]* 圆初始化列
CircleInitColumn :=[gen_tuple_const(6,348),gen_tuple_const(6,438)]*根据每个输入点交叉的形状创键一个XLD轮廓;
gen_cross_contour_xld (Cross1, CircleInitRow, CircleInitColumn,6,0.785398)* 直接规定变量
* 圆初始半径
CircleInitRadius :=[gen_tuple_const(6,23),gen_tuple_const(6,23)]* 半径公差
CircleRadiusTolerance :=12*Define the approximate position and the measure
* tolerance for the rectangles
* 定义矩形的近似位置和测量公差
* 矩形初始化行和列
RectangleInitRow :=[410,410]
RectangleInitColumn :=[215,562]
RectangleInitPhi :=[0,0]
RectangleInitLength1 :=[85,85]
RectangleInitLength2 :=[88,88]
RectangleTolerance :=10** 准备计量模型数据结构
*Prepare the metrology model data structure
*创建计量模型
create_metrology_model (MetrologyHandle)* 不需要预先设置图像宽度,但是可以改善第一次测量的运行时间。
*Setting the image width in advance is not
* necessary, but improves the runtime of the
* first measurement.
set_metrology_model_image_size (MetrologyHandle, Width, Height)* 将度量矩形对象添加上面定义的到模型中
*Add the metrology rectangle objects to the model
*as defined above
*(计量模型,矩形中心的行(或 y)坐标,矩形中心的列(或 x)坐标,矩形中心的列(或 x)坐标,主轴的方向,矩形较大半边的长度,矩形较小的半边的长度,)
add_metrology_object_rectangle2_measure (MetrologyHandle, RectangleInitRow, RectangleInitColumn, RectangleInitPhi, RectangleInitLength1, RectangleInitLength2, RectangleTolerance,5,.5,1,[],[], MetrologyRectangleIndices)* 将计量圆对象添加到上面定义的模型中
*Add the metrology circle objects to the model
*as defined above
add_metrology_object_circle_measure (MetrologyHandle, CircleInitRow, CircleInitColumn, CircleInitRadius, CircleRadiusTolerance,5,1.5,2,[],[], MetrologyCircleIndices)* 可以测量多个圆/矩形/直线/椭圆一次调用中每个度量对象的实例。
* 由于我们喜欢对每个物体测量两个圆圈,我们将“ num_instances”设置为2。
*Itis possible to measure more than one circle/rectangle/line/ellipse
* instance per metrology objectin one call.*Since we like to measure two circles per object,* we set'num_instances' to 2.* 设置测量模型参数
set_metrology_object_param (MetrologyHandle, MetrologyCircleIndices,'num_instances',2)* 将'measure_transition'设置为'uniform'可以确保仅返回一致的圆,圆的边缘只有从亮到暗的边缘,
* 反之亦然。由于一致性检查会增加运行时间,因此默认情况下将其关闭。
* 但是,在此示例中,由于同时存在负边缘和正边缘,因此将其打开更安全。
* Setting 'measure_transition' to 'uniform' assures
* that only consistent circles are returned, that have
* either only edges from bright to dark or vice versa.*Since the consistency check increases runtime, it is* switched of by default.*Inthis example however, it is safer to switch it on,* because both negative and positive edges are present.
set_metrology_object_param (MetrologyHandle, MetrologyCircleIndices,'measure_transition','uniform')* 设置最低分数可以使结果更可靠
*Setting the minimum score can make the results more robust
set_metrology_object_param (MetrologyHandle, MetrologyCircleIndices,'min_score',.9)** 执行测量
*Perform the measurement
** 测量并拟合度量模型中所有度量对象的几何形状
apply_metrology_model (Image, MetrologyHandle)** 获取计量模型的测量结果
get_metrology_object_result (MetrologyHandle, MetrologyRectangleIndices,'all','result_type','all_param', RectangleParameter)* 提取参数以提高可读性
*Extract the parameters for better readability
Sequence :=[0:5:|RectangleParameter|-1]
RectangleRow := RectangleParameter[Sequence]
RectangleColumn := RectangleParameter[Sequence+1]
RectanglePhi := RectangleParameter[Sequence+2]
RectangleLength1 := RectangleParameter[Sequence+3]
RectangleLength2 := RectangleParameter[Sequence+4]** 访问圆的测量结果
*Access the results of the circle measurement
get_metrology_object_result (MetrologyHandle, MetrologyCircleIndices,'all','result_type','all_param', CircleParameter)*Extract the parameters for better readability
Sequence :=[0:3:|CircleParameter|-1]
CircleRow := CircleParameter[Sequence]
CircleColumn := CircleParameter[Sequence+1]
CircleRadius := CircleParameter[Sequence+2]** 显示结果
*Display the results
** 获取测量轮廓
*Get measured contours
* 查询度量对象的结果轮廓
get_metrology_object_result_contour (Contours, MetrologyHandle,'all','all',1.5)* 获取测量区域的轮廓和边缘点的坐标
* 这是拟合圆形和矩形的基础
*Get the contours of the measure regions
* and the coordinates of the edge points
* that were the basis for fitting the circles and rectangles
* 获取度量模型的度量对象的度量区域和边缘位置的结果
get_metrology_object_measures (Contour, MetrologyHandle,'all','all', Row1, Column1)* 为每个输入点生成一个十字形的XLD轮廓
gen_cross_contour_xld (Cross, Row1, Column1,6,0.785398)*Display everything
Color :=['gray','cyan','green']
dev_display (Image)
dev_set_line_width (1)
dev_set_color (Color[0])
dev_display (Contour)
dev_set_color (Color[1])
dev_display (Cross)
dev_set_line_width (2)
dev_set_color (Color[2])
dev_display (Contours)
Message := Color[2]+': Measurement result'
Message[1]:= Color[1]+': Edge candidate points'
Message[2]:= Color[0]+': Measure regions'
disp_message (WindowHandle, Message,'window',12,12,'black','true')
stop ()*Clean up memory
clear_metrology_model (MetrologyHandle)
* This example shows the usage of the metrology model* to measure circles and rectangles with subpixel* accuracy under challenging conditions easily.* * Display initializations*停止刷新dev_update_off ()*读取不同文件格式的图像read_image (Image, 'pads')*获取图像的大小ge