赞
踩
一、读取3D模型文件,并采样生成对应的模板文件
在这里插入代码片 dev_get_window (WindowHandle) *读取3D模型 read_object_model_3d('C:/Users/VIBOT/Desktop/img_tmp/3d缺陷检测/A319空中客机_A319空中客机1.stl', 'mm', 'convert_to_triangles', 'true', ObjectModel3D, Status) Title := 'Reference object (uncalibrated measurement)' Instructions[0] := 'Rotate: Left button' Instructions[1] := 'Zoom: Shift + left button' Instructions[2] := 'Move: Ctrl + left button' *显示3D模型 visualize_object_model_3d (WindowHandle, ObjectModel3D, [], [], [], [], Title, [], Instructions, PoseOut) *计算三维对象模型的三维曲面法线 surface_normals_object_model_3d (ObjectModel3D, 'mls', 'mls_force_inwards', 'true', ObjectModel3DNormals) *3D模型的最大直径 max_diameter_object_model_3d (ObjectModel3DNormals, Diameter) *对3D模型采样 sample_object_model_3d (ObjectModel3DNormals, 'fast', Diameter * 0.005, [], [], Model3DSampled) * visualize_object_model_3d (WindowHandle, Model3DSampled, [], [], [], [], Title, [], Instructions, PoseOut) *创建基于表面匹配所需的数据结构。 create_surface_model (ObjectModel3DNormals, 0.03, 'model_invert_normals', 'true', SurfaceModelID)
二、一次读取3D的模型文件进行配准显示差异
for SceneIndex := 1 to NumScenes by 1 read_object_model_3d('C:/Users/VIBOT/Desktop/img_tmp/3d缺陷检测/quexian_fly/tmp'+ SceneIndex$'01d'+'.STL', 'mm', 'convert_to_triangles', 'true', Scene3D, Status) rigid_trans_object_model_3d (Scene3D, Pose, ObjectModel3DRigidTrans) sample_object_model_3d (ObjectModel3DRigidTrans, 'fast', Diameter * 0.005, [], [], Model3DScene3D) find_surface_model (SurfaceModelID, Model3DScene3D, 0.02, 0.2, 0, 'false', [], [], Pose, Score, NotUsed) refine_surface_model_pose (SurfaceModelID, Model3DScene3D, Pose, 0, 'false', [], [], Pose, Score, SurfaceMatchingResultID) *反转姿势 pose_invert (Pose, PosesInvert) *刚性变换 rigid_trans_object_model_3d (Model3DScene3D, PosesInvert, ObjectModel3DRigidTrans) *visualize_object_model_3d (WindowHandle1, [ObjectModel3DRigidTrans,Model3DSampled], [], [], [], [], Title, [], Instructions, PoseOut) * Measure the distances between the scene and the model.测量场景和模型之间的距离。 *计算一个 3D 对象模型的点到另一个 3D 对象模型的距离 * 'signed_distances' 该参数可用于计算三维对象模型ObjectModel3DFrom中的点到三维对象模型ObjectModel3DTo中的点、三角形或原语的带符号距离。 distance_object_model_3d (ObjectModel3DRigidTrans, Model3DSampled, [], 0.0, 'signed_distances', 'true') * Select points with a high distance below the model * (negative distance) and the points above the model * (positive distance). *.选择模型下方距离较大的点(负距离)和模型上方距离较大的点(正距离)。 select_points_object_model_3d (ObjectModel3DRigidTrans, '&distance', -1000, -0.0003, ObjectModel3DThresholdedUp) select_points_object_model_3d (ObjectModel3DRigidTrans, '&distance', 0.0003, 1000, ObjectModel3DThresholdedDown) *visualize_object_model_3d (WindowHandle1,[ObjectModel3DThresholdedUp], [], [], [], [], Title, [], Instructions, PoseOut) * Calculate connected components of the points below * (negative distance) and the connected components of the * points above (positive distance) the model. * The distance threshold should be greater than the distance * between two scanlines (> ScaleY). *计算模型下方(负距离)点的连接组件和上方(正距离)点的连接组件。 * 距离阈值应大于两条扫描线之间的距离(>ScaleY)。 *'distance_3d' : 测试 3D 点集的点坐标之间的欧氏距离。对于低于值值的任何距离,这些点被视为连接点。 * 小于ScaleY + 5 阈值的作为连接点 connection_object_model_3d (ObjectModel3DThresholdedUp, 'distance_3d', 0.01, ObjectModel3DConnectedUp) connection_object_model_3d (ObjectModel3DThresholdedDown, 'distance_3d', 0.01, ObjectModel3DConnectedDown) * Keep the large components, discard small ones as noise.保留大部件,丢弃小部件作为噪声。 select_object_model_3d (ObjectModel3DConnectedUp, 'num_points', 'and', 20, 1000000, ObjectModel3DSelectedUp) select_object_model_3d (ObjectModel3DConnectedDown, 'num_points', 'and', 20, 1000000, ObjectModel3DSelectedDown) * Set the visualization parameters and values depending on * the position of the error points. NumErrors := |ObjectModel3DSelectedDown| + |ObjectModel3DSelectedUp| Title := 'Found ' + NumErrors + ' error(s)' ErrorColorUp := 'blue' ErrorColorDown := 'red' ErrorColorNames := 'color_' + [2:NumErrors + 1] VisParamNames := ['point_size','point_size_1','color_0','color_1',ErrorColorNames,'alpha_' + NumErrors,'disp_background'] VisParamValues := [5.0,2.0,'white','green',gen_tuple_const(|ObjectModel3DSelectedUp|,ErrorColorUp),gen_tuple_const(|ObjectModel3DSelectedDown|,ErrorColorDown),0.8,'true'] * Display the errorneous regions. dev_clear_window () *disp_message (WindowHandle, ['Bent up','Bent down'], 'window', 12, 500, [ErrorColorUp,ErrorColorDown], 'false') visualize_object_model_3d (WindowHandle1, [ObjectModel3DNormals,ObjectModel3DRigidTrans,ObjectModel3DSelectedUp,ObjectModel3DSelectedDown], [], [], VisParamNames, VisParamValues, Title, ['','','#' + [1:NumErrors]], Instructions, PoseOut1) endfor
三、效果展示
蓝色为模型相对于3D模板多出的部分
红色为模型相对于3D模板缺少的部分
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。