halcon例程解析一 apply

tech2022-10-12  99

]

dev_update_off () 设备更新关闭() read_image (Image, 'pads') 读取图像(图像,“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] CircleIntrow:=[行循环,行循环] CircleInitColumn := [gen_tuple_const(6,348),gen_tuple_const(6,438)] CircleInitColumn:=[生成元组常量(6348),生成元组常量(6438] gen_cross_contour_xld (Cross1, CircleInitRow, CircleInitColumn, 6, 0.785398) 生成十字星表示坐标位置及生成交叉方向的XLD轮廓(生成XLD轮廓,输入点的行坐标,列,十字大小,十字角度) 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] 矩形初始化行:=[410410] RectangleInitColumn := [215,562] 矩形初始化列:=[215562] RectangleInitPhi := [0,0] RectangleInitLength1 := [85,85] 矩形初始长度1 RectangleInitLength2 := [88,88] 矩形初始长度2 RectangleTolerance := 10 矩形公差:=10 Prepare the metrology model data structure 准备计量模型数据结构 create_metrology_model (MetrologyHandle) 生成检测模型,metrology:卡尺 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 将定义的矩形加入到计量模型中 add_metrology_object_rectangle2_measure (MetrologyHandle, RectangleInitRow, RectangleInitColumn, RectangleInitPhi, RectangleInitLength1, RectangleInitLength2, RectangleTolerance, 5, .5, 1, [], [], MetrologyRectangleIndices) *增加卡尺模型(卡尺模型,行,列,角度,长,宽,公差,与边界相切的检测区域的一般长度,Sigma的高斯函数用于平滑,最小边幅,用于参数的名称,创建的计量对象的索引) 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) *增加卡尺模型(卡尺模型,行,列,半径,半径公差,与边界相切的检测区域的一般长度,Sigma的高斯函数用于平滑,最小边幅,用于参数的名称,创建的计量对象的索引) * It is possible to measure more than one circle/rectangle/line/ellipse * instance per metrology object in one call. * Since we like to measure two circles per object, * we set 'num_instances' to 2. *在一次调用中可每个计量对象可以测量多个圆/矩形/直线/椭圆本例中设置圆的数目为2 set_metrology_object_param (MetrologyHandle, MetrologyCircleIndices, 'num_instances', 2) 设置测量模型参数 * 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. * In this example however, it is safer to switch it on, * because both negative and positive edges are present. 将“measure_transition”设置为“uniform”可确保只返回一致的圆,这些圆要么只有从亮到暗的边,要么反之亦然。 由于一致性检查会增加运行时间,因此默认情况下会切换为。但是在这个例子中,打开它更安全,因为同时存在负边和正边。 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) *得到计量模型的测量区域和边缘定位结果(给定度量对象的结果轮廓,计量对象的索引,选择深色/浅色边缘,测量边缘的行,列坐标) 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') 编辑一条文本消息(要显示文本消息的字符串数组,相对于坐标系给出文本位置,文本的行列,true文本将显示在文本框中,false不显示框) stop () * Clean up memory clear_metrology_model (MetrologyHandle) 释放句柄
最新回复(0)