*显示初始化 dev_update_off () read_image (Image , ‘C:/Users/29540/Desktop/circleRectangle.png’) *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’) * *定义圆的近似位置和测量公差 RowCircle := [52:89:500] CircleInitRow := [RowCircle,RowCircle] CircleInitColumn := [gen_tuple_const(6,348),gen_tuple_const(6,438)] gen_cross_contour_xld (Cross1, CircleInitRow, CircleInitColumn, 6, 0.785398) CircleInitRadius := [gen_tuple_const(6,23),gen_tuple_const(6,23)] CircleRadiusTolerance := 12 *定义矩形的近似位置和测量公差 RectangleInitRow := [410,410] RectangleInitColumn := [215,562] RectangleInitPhi := [0,0] RectangleInitLength1 := [85,85] RectangleInitLength2 := [88,88] RectangleTolerance := 10 * *编制计量模型数据结构 create_metrology_model (MetrologyHandle) * *预先设置图像宽度是不必要的,但可以改善第一次测量的运行时间 set_metrology_model_image_size (MetrologyHandle, Width, Height) * *添加计量矩形对象到模式,正如上面定义的 add_metrology_object_rectangle2_measure (MetrologyHandle, RectangleInitRow, RectangleInitColumn, RectangleInitPhi, RectangleInitLength1, RectangleInitLength2, RectangleTolerance, 5, .5, 1, [], [], MetrologyRectangleIndices) * *将计量圆对象添加到上述定义的模型中 add_metrology_object_circle_measure (MetrologyHandle, CircleInitRow, CircleInitColumn, CircleInitRadius, CircleRadiusTolerance, 5, 1.5, 2, [], [], MetrologyCircleIndices) *可以在一个调用中度量每个度量对象的多个圆/矩形/线/椭圆实例 *因为我们喜欢测量每个对象的两个圆,所以我们将’num_instances’设置为2 set_metrology_object_param (MetrologyHandle, MetrologyCircleIndices, ‘num_instances’, 2)
将“测量-过渡”设置为“均匀”确保只有一致的圆圈返回,那有要么只是从亮到暗的边缘,要么相反因为一致性检查会在运行时增加,所以确实如此在默认情况下切换为然而,在本例中,打开它更安全,因为正负边都存在 set_metrology_object_param (MetrologyHandle, MetrologyCircleIndices, ‘measure_transition’, ‘uniform’)设置最低分数可以使结果更加可靠 set_metrology_object_param (MetrologyHandle, MetrologyCircleIndices, ‘min_score’, .9)*性能测量 * apply_metrology_model (Image, MetrologyHandle) * get_metrology_object_result (MetrologyHandle, MetrologyRectangleIndices, ‘all’, ‘result_type’, ‘all_param’, RectangleParameter)
提取参数以提高可读性 Sequence := [0:5:|RectangleParameter| - 1] RectangleRow := RectangleParameter[Sequence] RectangleColumn := RectangleParameter[Sequence + 1] RectanglePhi := RectangleParameter[Sequence + 2] RectangleLength1 := RectangleParameter[Sequence + 3] RectangleLength2 := RectangleParameter[Sequence + 4]*查看圆的测量结果 get_metrology_object_result (MetrologyHandle, MetrologyCircleIndices, ‘all’, ‘result_type’, ‘all_param’, CircleParameter) *提取参数以提高可读性 Sequence := [0:3:|CircleParameter| - 1] CircleRow := CircleParameter[Sequence] CircleColumn := CircleParameter[Sequence + 1] CircleRadius := CircleParameter[Sequence + 2] *
显示结果得到测量轮廓 get_metrology_object_result_contour (Contours, MetrologyHandle, ‘all’, ‘all’, 1.5)得到测量区域的轮廓和边缘点的坐标,作为拟合圆和矩形的基础 get_metrology_object_measures (Contour, MetrologyHandle, ‘all’, ‘all’, Row1, Column1) gen_cross_contour_xld (Cross, Row1, Column1, 6, 0.785398)显示所有 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)