网站开发的,驾校网站模版,手机 pc网站开发价格,亚马逊网站托管怎么做HALCON算子 get_metrology_object_result_contour 全解析
一、算子核心定位
get_metrology_object_result_contour 是HALCON 2D计量#xff08;2D Metrology#xff09;模块的可视化核心算子#xff0c;核心功能是获取经apply_metrology_model拟合后的计量对象实例的结果轮廓…HALCON算子get_metrology_object_result_contour全解析一、算子核心定位get_metrology_object_result_contour是HALCON 2D计量2D Metrology模块的可视化核心算子核心功能是获取经apply_metrology_model拟合后的计量对象实例的结果轮廓XLD形式——它基于拟合后的几何参数如圆的圆心/半径、矩形的中心/角度/尺寸生成对应形状的亚像素XLD轮廓是将抽象的测量数值转化为直观可视化轮廓的关键工具常用于验证拟合结果的形状/位置是否符合预期。二、算法核心原理有效性校验验证输入的计量模型句柄MetrologyHandle、计量对象索引Index、实例编号Instance的有效性确保指向已完成拟合的计量对象/实例拟合参数读取从计量模型中读取指定对象/实例的拟合几何参数如圆的row/column/radius、矩形的row/column/phi/length1/length2轮廓生成根据几何参数和Resolution相邻轮廓点距离生成对应形状的亚像素XLD轮廓圆形/椭圆按分辨率均匀生成圆周/椭圆周的轮廓点矩形/直线按分辨率生成边的轮廓点分辨率约束若输入的Resolution低于最小有效值1.192e-7自动将其重置为该最小值结果返回将生成的XLD轮廓按“先第一个对象的所有实例再第二个对象的所有实例”的顺序封装为数组输出到Contour参数无修改逻辑仅生成并返回轮廓不改变计量模型/对象的任何属性。三、参数全详解一输入参数Input Parameters参数名类型功能说明默认值关键取值规则注意事项MetrologyHandlemetrology_model → (handle)指定要查询的2D计量模型句柄-必须为已有效创建/加载的计量模型句柄1. 需通过create_metrology_model生成未被clear_metrology_model释放2. 无效句柄直接抛出“句柄无效”异常Indexinteger(-array) → (integer / string)指定要查询的计量对象索引0可选值▪ ‘all’查询模型内所有计量对象的轮廓▪ 整数/整数数组查询指定索引的计量对象如0、[0,1]整数索引必须是get_metrology_object_indices返回的有效索引否则抛异常Instanceinteger(-array) → (string / integer)指定要查询的实例编号‘all’可选值▪ ‘all’查询指定计量对象的所有实例轮廓▪ 整数/整数数组查询指定实例如0、[0,1]1. 实例编号从0开始需≤get_metrology_object_num_instances返回的实例数-12. 若实例不存在如指定1但仅检测到1个实例抛异常Resolutionreal → (real)轮廓相邻点的欧氏距离像素1.5取值规则▪ 最小值1.192e-7▪ 推荐值1.0~5.0兼顾精度与效率▪ 约束Resolution ≥ 1.192e-71. 值越小轮廓点越多、形状越精细但生成速度越慢2. 低于最小值时算子自动重置为1.192e-7二输出参数Output Parameters参数名类型功能说明关联说明Contourxld_cont(-array) → object返回拟合后的XLD轮廓数组1. 每个实例对应一个XLD轮廓2. 轮廓坐标为图像像素坐标不受相机参数影响3. 顺序先第一个计量对象的所有实例再第二个计量对象的所有实例4. 可直接用dev_display可视化四、使用关键注意事项执行时序约束必须在调用apply_metrology_model完成拟合后调用本算子否则Contour返回空数组若拟合未找到目标实例数为0也返回空数组分辨率权衡高分辨率小值如0.5轮廓更精细适合高精度可视化但生成耗时更长低分辨率大值如5.0轮廓点数少生成快适合快速预览默认值1.5是“精度-效率”的平衡值满足大部分场景需求坐标特性生成的轮廓始终以像素为单位即使设置了相机参数/测量平面公制坐标也不会转换为公制仅反映图像中的像素位置多线程特性多线程类型可重入能与非排他算子并行运行多线程范围全局可从任意线程调用无并行优化仅单线程生成轮廓无性能加速返回值规则执行成功返回2H_MSG_TRUE参数无效如索引/实例错误、Resolution低于最小值且未自动修正时直接抛出异常。五、算子调用链路一前置算子Possible Predecessorscreate_metrology_model创建空的2D计量模型基础前置add_metrology_object_*如add_metrology_object_rectangle2_measure/add_metrology_object_circle_measure向模型添加计量对象apply_metrology_model执行检测拟合生成轮廓的必要前置get_metrology_object_num_instances可选获取实例数用于精准指定Instance。二后置算子Possible Successorsdev_display可视化显示轮廓验证拟合结果的形状/位置gen_region_contour_xld将XLD轮廓转化为区域用于后续形态学操作clear_metrology_model释放计量模型句柄收尾操作。六、与相似算子的核心差异算子名称核心区别适用场景get_metrology_object_result_contour返回拟合后的目标轮廓XLD基于拟合参数生成可视化拟合结果的形状/位置、验证拟合精度get_metrology_object_result返回拟合后的数值参数如圆心、半径、角度获取精准的测量数值、用于尺寸判定/计算get_metrology_object_measures返回测量区域轮廓原始边缘点坐标无拟合逻辑调试测量区域范围、验证原始边缘检测结果七、典型应用示例HDevelop 代码*This example shows the usage of the metrology model*to measure circles and rectangles with subpixel*accuracy under challenging conditions easily.**Display initializationsdev_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*toleranceforthe circles 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*Define the approximate position and the measure*toleranceforthe rectangles2 RectangleInitRow:[410,410]RectangleInitColumn:[215,562]RectangleInitPhi:[0,0]RectangleInitLength1:[85,85]RectangleInitLength2:[88,88]RectangleTolerance:10**Prepare the metrology model data structurecreate_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 aboveadd_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 aboveadd_metrology_object_circle_measure(MetrologyHandle,CircleInitRow,CircleInitColumn,CircleInitRadius,CircleRadiusTolerance,5,1.5,2,[],[],MetrologyCircleIndices)*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 setnum_instancesto2.set_metrology_object_param(MetrologyHandle,MetrologyCircleIndices,num_instances,2)*Settingmeasure_transitiontouniformassures*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 bydefault.*In this example however,it is safer toswitchit 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 robustset_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 parametersforbetter readability Sequence:[0:5:|RectangleParameter|-1]RectangleRow:RectangleParameter[Sequence]RectangleColumn:RectangleParameter[Sequence1]RectanglePhi:RectangleParameter[Sequence2]RectangleLength1:RectangleParameter[Sequence3]RectangleLength2:RectangleParameter[Sequence4]**Access the results of the circle measurementget_metrology_object_result(MetrologyHandle,MetrologyCircleIndices,all,result_type,all_param,CircleParameter)*Extract the parametersforbetter readability Sequence:[0:3:|CircleParameter|-1]CircleRow:CircleParameter[Sequence]CircleColumn:CircleParameter[Sequence1]CircleRadius:CircleParameter[Sequence2]**Display the results**Get measured contoursget_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 basisforfitting the circles and rectanglesget_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 resultMessage[1]:Color[1]: Edge candidate pointsMessage[2]:Color[0]: Measure regionsdisp_message(WindowHandle,Message,window,12,12,black,true)stop()*Clean up memoryclear_metrology_model(MetrologyHandle)八、总结关键点回顾get_metrology_object_result_contour核心作用是基于拟合参数生成可视化XLD轮廓是将数值测量结果转化为直观形状的关键工具Resolution控制轮廓精细度值越小越精细最小值为1.192e-7低于该值会自动重置轮廓始终以像素坐标返回需在apply_metrology_model后调用否则返回空轮廓。