当前位置: 首页 > article >正文

Halcon 3D加快表面匹配速度

文章目录

  • gen_box_object_model_3d 创建一个代表盒子的 3D 物体模型
  • write_surface_model — 将表面模型写入文件
  • read_surface_model — 将表面模型读取
  • prepare_object_model_3d - 为某个操作准备三维对象模型
  • select_points_object_model_3d - 对 3D 物体模型的属性应用阈值。
  • set_surface_model_param - 设置曲面模型的参数和属性。
  • 示例
  • [Halcon 3D表面匹配](https://blog.csdn.net/weixin_45672157/article/details/143465086)

gen_box_object_model_3d 创建一个代表盒子的 3D 物体模型

gen_box_object_model_3d( : : Pose, LengthX, LengthY, LengthZ : ObjectModel3D)
### Pose (输入控制)
- **类型**: 实数/整数数组
- **描述**: 描述盒子位置和方向的姿态。姿态的原点位于盒子的中心。
- **解释**:- 这个参数是一个包含姿态的数组。每个姿态描述了盒子的位置和方向,其原点位于盒子的中心。### LengthX (输入控制)
- **类型**: 实数数组
- **描述**: 盒子沿x轴的长度。
- **解释**:- 这个参数是一个实数数组,包含盒子沿x轴的长度。每个长度对应一个盒子。### LengthY (输入控制)
- **类型**: 实数数组
- **描述**: 盒子沿y轴的长度。
- **元素数量**: LengthY 的元素数量等于 LengthX 的元素数量。
- **解释**:- 这个参数是一个实数数组,包含盒子沿y轴的长度。每个长度对应一个盒子。### LengthZ (输入控制)
- **类型**: 实数数组
- **描述**: 盒子沿z轴的长度。
- **元素数量**: LengthZ 的元素数量等于 LengthX 的元素数量。
- **解释**:- 这个参数是一个实数数组,包含盒子沿z轴的长度。每个长度对应一个盒子。### ObjectModel3D (输出控制)
- **类型**: 整数数组
- **描述**: 生成的3D对象模型的句柄。
- **解释**:- 这个参数是一个整数数组,表示生成的3D对象模型的句柄。通过这些句柄,可以访问和操作生成的3D对象模型。

write_surface_model — 将表面模型写入文件

write_surface_model( : : SurfaceModelID, FileName : )
### SurfaceModelID (输入控制)
- **类型**: 整数
- **描述**: 表面模型的句柄。
- **解释**:- 这个参数是一个整数,表示表面模型的句柄。通过这个句柄,可以访问和操作表面模型。### FileName (输入控制)
- **类型**: 字符串
- **描述**: 文件名。
- **文件扩展名**: .sfm
- **解释**:- 这个参数指定保存表面模型的文件名。文件扩展名应为 `.sfm`,表示表面模型文件。

read_surface_model — 将表面模型读取

read_surface_model( : : FileName : SurfaceModelID)
### FileName (输入控制)
- **类型**: 字符串
- **描述**: SFM 文件的名称。
- **文件扩展名**: .sfm
- **解释**:- 这个参数指定要读取的 SFM 文件的名称。文件扩展名应为 `.sfm`,表示表面模型文件。### SurfaceModelID (输出控制)
- **类型**: 整数
- **描述**: 读取的表面模型的句柄。
- **解释**:- 这个参数是一个整数,表示读取的表面模型的句柄。通过这个句柄,可以访问和操作读取的表面模型。

prepare_object_model_3d - 为某个操作准备三维对象模型

prepare_object_model_3d( : : ObjectModel3D, Purpose, OverwriteData, GenParamName, GenParamValue : )
### ObjectModel3D (输入控制)
- **类型**: 整数数组
- **描述**: 3D对象模型的句柄。
- **解释**:- 这个参数是一个整数数组,表示一个或多个3D对象模型的句柄。通过这些句柄,可以访问和操作这些3D对象模型。### Purpose (输入控制)
- **类型**: 字符串
- **描述**: 3D对象模型的用途。
- **默认值**: 'shape_based_matching_3d'
- **建议值**:- 'shape_based_matching_3d': 基于形状的3D匹配。- 'segmentation': 分割。- 'distance_computation': 距离计算。
- **解释**:- 这个参数指定3D对象模型的用途。不同的用途会影响数据的处理和存储方式。### OverwriteData (输入控制)
- **类型**: 字符串
- **描述**: 指定是否覆盖已存在的数据。
- **默认值**: 'true'
- **可选值**:- 'false': 不覆盖。- 'true': 覆盖。
- **解释**:- 这个参数指定是否覆盖已存在的数据。如果设置为'true',则覆盖已存在的数据;如果设置为'false',则保留已存在的数据。### GenParamName (输入控制)
- **类型**: 字符串/实数/整数数组
- **描述**: 通用参数的名称。
- **默认值**: []
- **可选值**:- 'distance_to': 距离到。- 'max_area_holes': 最大面积孔洞。- 'max_distance': 最大距离。- 'method': 方法。- 'sampling_dist_abs': 采样距离绝对值。- 'sampling_dist_rel': 采样距离相对值。
- **解释**:- 这个参数指定通用参数的名称。通过这些参数,可以进一步控制3D对象模型的处理过程。### GenParamValue (输入控制)
- **类型**: 字符串/实数/整数数组
- **描述**: 通用参数的值。
- **默认值**: []
- **建议值**:- 0, 1, 100, 'auto', 'triangles', 'points', 'primitive', 'kd-tree', 'voxel', 'linear', 0.01, 0.03
- **解释**:- 这个参数指定通用参数的值。通过这些值,可以进一步控制3D对象模型的处理过程。

select_points_object_model_3d - 对 3D 物体模型的属性应用阈值。

select_points_object_model_3d( : : ObjectModel3D, Attrib, MinValue, MaxValue : ObjectModel3DThresholded)
### ObjectModel3D (输入控制)
- **类型**: 整数数组
- **描述**: 3D对象模型的句柄。
- **解释**:- 这个参数是一个整数数组,表示一个或多个3D对象模型的句柄。通过这些句柄,可以访问和操作这些3D对象模型。### Attrib (输入控制)
- **类型**: 字符串数组
- **描述**: 应用阈值的属性。
- **默认值**: 'point_coord_z'
- **可选值**:- 'mapping_col': 映射列。- 'mapping_row': 映射行。- 'neighbor_distance': 邻居距离。- 'num_neighbors': 邻居数量。- 'num_neighbors_fast': 快速计算的邻居数量。- 'point_coord_x': 点的X坐标。- 'point_coord_y': 点的Y坐标。- 'point_coord_z': 点的Z坐标。- 'point_normal_x': 点法线的X分量。- 'point_normal_y': 点法线的Y分量。- 'point_normal_z': 点法线的Z分量。
- **解释**:- 这个参数指定应用阈值的属性。通过这些属性,可以筛选出符合条件的3D对象模型。### MinValue (输入控制)
- **类型**: 实数/整数数组
- **描述**: 属性指定的最小值。
- **默认值**: 0.5
- **解释**:- 这个参数指定属性指定的最小值。通过这个值,可以筛选出符合最小值条件的3D对象模型。### MaxValue (输入控制)
- **类型**: 实数/整数数组
- **描述**: 属性指定的最大值。
- **默认值**: 1.0
- **解释**:- 这个参数指定属性指定的最大值。通过这个值,可以筛选出符合最大值条件的3D对象模型。### ObjectModel3DThresholded (输出控制)
- **类型**: 整数数组
- **描述**: 减少的3D对象模型的句柄。
- **解释**:- 这个参数是一个整数数组,表示减少的3D对象模型的句柄。通过这些句柄,可以访问和操作减少后的3D对象模型。

set_surface_model_param - 设置曲面模型的参数和属性。

set_surface_model_param( : : SurfaceModelID, GenParamName, GenParamValue : )
### SurfaceModelID (输入控制)
- **类型**: 整数
- **描述**: 表面模型的句柄。
- **解释**:- 这个参数是一个整数,表示表面模型的句柄。通过这个句柄,可以访问和操作表面模型。### GenParamName (输入控制)
- **类型**: 字符串
- **描述**: 参数的名称。
- **默认值**: 'camera_parameter'
- **可选值**:- 'camera_parameter': 相机参数。- 'camera_pose': 相机姿态。- 'clear_cameras': 清除相机。
- **解释**:- 这个参数指定要设置的参数的名称。通过这些名称,可以设置或查询表面模型的相机参数或姿态。### GenParamValue (输入控制)
- **类型**: 实数/字符串/整数数组
- **描述**: 参数的值。
- **解释**:- 这个参数指定参数的值。根据参数名称,可以设置或查询相应的相机参数、姿态或清除相机。

示例

在这里插入图片描述

  • create_surface_model (ObjectModel3DModel, 0.03, ‘train_3d_edges’, ‘true’, SurfaceModel)train_3d_edges训练3D边缘增加识别精确度
  • select_points_object_model_3d (ObjectModel3DScene, ‘point_coord_z’, 0.1, 0.73, SceneWithoutBackground)移除背景增加匹配速度
  • find_surface_model (SurfaceModel, ObjectModel3DScene, 0.05, 0.1, MinScore, ‘false’, [‘num_matches’,‘pose_ref_sub_sampling’], [3,20], Pose, Score, SurfaceMatchingResult)pose_ref_sub_sampling增加查找速度
  • set_surface_model_param (SurfaceModel, ‘camera_parameter’, CameraParam)
  • set_surface_model_param (SurfaceModel, ‘camera_pose’, CameraPose) 条件相机
dev_update_off ()
* 
* Parameters of the 2D camera.
* 设置相机参数
gen_cam_par_area_scan_division (0.003, -22215.7, 1e-6, 1e-6, 629.3, 486.95, 1280, 960, CameraParam)
get_cam_par_data (CameraParam, 'image_width', Width)
get_cam_par_data (CameraParam, 'image_height', Height)
* The camera is located in the origin of the 3D sensor.
create_pose (0, 0, 0, 0, 0, 0, 'Rp+T', 'gba', 'point', CameraPose)
* Matching parameters.
* 最小匹配得分参数
MinScore := 0.2
* Visualization parameters.
* 创建位姿
create_pose (-0.075, -0.56, 4.4, 308, 6, 335, 'Rp+T', 'gba', 'point', VisPose)
VisParamNames := ['color','color_0','alpha','alpha_0']
VisParamValues := ['red','white',0.5,1]
WidthW1 := 400
LineLength := 32
VisRowNextStep := 300
VisInstructions[0] := 'Rotate: Left button'
VisInstructions[1] := 'Zoom:   Shift + left button'
VisInstructions[2] := 'Move:   Ctrl  + left button'
* Prepare windows.
dev_close_window ()
dev_open_window_fit_size (0, WidthW1 + 10, Width, Height, 640, 480, WindowHandle2)
get_window_extents (WindowHandle2, Row, Column, WidthW2, HeightW2)
dev_open_window (0, 0, WidthW1, HeightW2, 'white', WindowHandle1)
set_display_font (WindowHandle1, 16, 'mono', 'true', 'false')
set_display_font (WindowHandle2, 16, 'mono', 'true', 'false')
* 
* Read image of the scene.
SceneIdx := 4
* 读取图片
read_image (Image, 'boxes/cardboard_boxes_02')
* 
* Display first message and the image of the scene.
dev_set_window (WindowHandle1)
dev_clear_window ()
Text := 'This example demonstrates edge-supported surface-based matching. The goal is to find cardboard boxes in 3D scans of the scene.'
wrap_text (Text, LineLength, TextWrapped)
dev_disp_text (TextWrapped, 'window', 'top', 'left', 'black', 'box', 'false')
dev_set_window (WindowHandle2)
dev_display (Image)
* 
* Create a 3D model of a box.
dev_set_window (WindowHandle1)
* 
gen_box_object_model_3d ([0,0,0,0,0,0,0], 0.103, 0.082, 0.05, ObjectModel3DBox)
* 平面三角化,加快匹配速度,获取包含三角剖分表面的3D对象模型的句柄ObjectModel3DModel
triangulate_object_model_3d (ObjectModel3DBox, 'greedy', [], [], ObjectModel3DModel, Information)
* 清除3D模型
clear_object_model_3d (ObjectModel3DBox)
* Prepare a model for edge-supported surface-based matching.
FileName := 'box_edge_supported.sfm'
file_exists (FileName, FileExists)
if (not FileExists)* 如果文件不存在 创建表面匹配模版dev_disp_text ('Creating new surface model.\nThis might take some minutes...', 'window', 150, 'left', 'black', 'box', 'false')******************************训练3D边缘信息create_surface_model (ObjectModel3DModel, 0.03, 'train_3d_edges', 'true', SurfaceModel)* 将模版写入write_surface_model (SurfaceModel, FileName)
elsedev_disp_text ('Reading pre-created surface model...', 'window', 150, 'left', 'black', 'box', 'false')* 读取表面模型read_surface_model (FileName, SurfaceModel)
endif
* 
* Create a 3D model of a box for surface-based matching without edge support.
* * 在没有边缘支持的情况下,为基于表面的匹配创建一个盒子的三维模型。
create_surface_model (ObjectModel3DModel, 0.03, [], [], SurfaceModelWithoutEdgeSupport)
* 
* Read the 3D object model of the search scene and prepare it for display.
* 读取搜索场景的 3D 物体模型并准备显示。
read_image (ImageXYZ, 'boxes/cardboard_boxes_xyz_02')
decompose3 (ImageXYZ, XScene, YScene, ZScene)
* 将点云转换为3D模型
xyz_to_object_model_3d (XScene, YScene, ZScene, ObjectModel3DScene)
* 准备3D
prepare_object_model_3d (ObjectModel3DScene, 'segmentation', 'true', [], [])
* 获取3D模型参数
get_object_model_3d_params (ObjectModel3DScene, 'center', VisRotationCenter)
* 
* Display search scene.
dev_set_window (WindowHandle1)
Text := 'First, let\'s have a look at the 3D data of the scene.'
wrap_text (Text, LineLength, TextWrapped)
dev_disp_text (TextWrapped, 'window', VisRowNextStep, 'left', 'black', 'box', 'false')
dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
stop ()
dev_clear_window ()
*在三维数据中,这两个方框显示为平面部分,明显位于地平面之上
Text := 'In the 3D data, the two boxes appear as planar parts that lie clearly above the ground plane.'
wrap_text (Text, LineLength, TextWrapped)
dev_disp_text (TextWrapped, 'window', 'top', 'left', 'black', 'box', 'false')
visualize_object_model_3d (WindowHandle2, ObjectModel3DScene, [], VisPose, [], [], '3D scene', [], VisInstructions, VisPose)
* 
* Show results of surface-based matching without edge support.
dev_set_window (WindowHandle1)
dev_clear_window ()
******不使用用边缘信息************************
*如果不使用边缘信息,有时会错误地找到平面物体。特别是如果搜索场景中的物体表面是破碎的,例如,由于表面反射的原因。
Text := 'Objects with a planar surface are sometimes found incorrectly if no edge information is used. Especially, if the surface of the object in the search scene is fragmented, e.g., because of reflections on the surface.'
wrap_text (Text, LineLength, TextWrapped)
dev_disp_text (TextWrapped, 'window', 'top', 'left', 'black', 'box', 'false')
* Perform surface-based matching without edge support.
** 执行基于表面的匹配,无需边缘支持。
find_surface_model (SurfaceModelWithoutEdgeSupport, ObjectModel3DScene, 0.05, 0.1, MinScore, 'false', 'num_matches', 1, Pose, Score, SurfaceMatchingResult)
* Display results.
* 显示匹配结果
rigid_trans_object_model_3d (ObjectModel3DModel, Pose, ObjectModel3DRigidTrans)
visualize_object_model_3d (WindowHandle2, [ObjectModel3DScene,ObjectModel3DRigidTrans], [], VisPose, VisParamNames, VisParamValues, 'Without edge support, a wrong match is found.', [], VisInstructions, VisPose)
clear_object_model_3d (ObjectModel3DRigidTrans)
*************************************************************************************使用边缘信息
* Show results of edge-supported surface-based matching.* 显示边缘支持的模版匹配结果
dev_set_window (WindowHandle1)
dev_clear_window ()
*在这种情况下,使用 3D 边缘(绿色显示)有助于找到正确的匹配。请注意,'num_matched/'已设置为 1,因此只找到一个方框。
Text := 'In those cases, the use of 3D edges (displayed in green) helps to find the correct match. Note that \'num_matches\' has been set to 1, therefore only one box is found.'
wrap_text (Text, LineLength, TextWrapped)
dev_disp_text (TextWrapped, 'window', 'top', 'left', 'black', 'box', 'false')
*'要使用基于边缘支持的曲面匹配,请在创建曲面模型时将通用参数 ('train_3d_edges/')设置为 ('true/')。
Text := 'To use edge-supported surface-based matching, create the surface model with the generic parameter \'train_3d_edges\' set to \'true\'.'
wrap_text (Text, LineLength, TextWrapped)
dev_disp_text (TextWrapped, 'window', 150, 'left', 'black', 'box', 'false')
* Perform edge-supported surface-based matching.
find_surface_model (SurfaceModel, ObjectModel3DScene, 0.05, 0.1, MinScore, 'false', 'num_matches', 1, Pose, Score, SurfaceMatchingResult)
* Extract edges for visualization.
* 提取边缘场景
get_object_model_3d_params (ObjectModel3DScene, 'diameter_axis_aligned_bounding_box', Diameter)
edges_object_model_3d (ObjectModel3DScene, 0.01 * Diameter, [], [], ObjectModel3DEdges)
* Display results.
rigid_trans_object_model_3d (ObjectModel3DModel, Pose, ObjectModel3DRigidTrans)
VisParamValues[0] := 'forest green'
visualize_object_model_3d (WindowHandle2, [ObjectModel3DScene,ObjectModel3DEdges,ObjectModel3DRigidTrans], [], VisPose, [VisParamNames,'color_1'], [VisParamValues,'green'], 'With edge support, the match is found correctly.', [], VisInstructions, VisPose)
clear_object_model_3d (ObjectModel3DRigidTrans)
* 
* Show results of edge-supported surface-based matching when searching for multiple matches.
* 显示匹配结果
dev_set_window (WindowHandle1)
dev_clear_window ()
*如果我们搜索到多个匹配项,第二个方框也会被找到。
Text := 'If we search for more than one match, the second box is found as well.'
wrap_text (Text, LineLength, TextWrapped)
dev_disp_text (TextWrapped, 'window', 'top', 'left', 'black', 'box', 'false')
Text := 'Note that additional matches may also be found in the corners of the 3D scene. The top plane of the box fits perfectly to the background plane of the scene and two of the top plane\'s edges match the 3D edges of the scene.'
wrap_text (Text, LineLength, TextWrapped)
dev_disp_text (TextWrapped, 'window', 150, 'left', 'black', 'box', 'false')
* Perform edge-supported surface-based matching.
** 执行边缘支持的曲面匹配。
find_surface_model (SurfaceModel, ObjectModel3DScene, 0.05, 0.1, MinScore, 'false', 'num_matches', 5, Pose, Score, SurfaceMatchingResult)
* Display results.
rigid_trans_object_model_3d (ObjectModel3DModel, Pose, ObjectModel3DRigidTrans)
visualize_object_model_3d (WindowHandle2, [ObjectModel3DScene,ObjectModel3DEdges,ObjectModel3DRigidTrans], [], VisPose, [VisParamNames,'color_1','color_4'], [VisParamValues,'green','red'], 'The boundaries of the scene lead to additional matches.', [], VisInstructions, VisPose)
clear_object_model_3d (ObjectModel3DRigidTrans)
* * 如果三维对象模型具有映射信息,则演示如何移除场景边界上的边缘。
* Show how to remove edges at the boundary of the scene if the 3D object model has mapping information.dev_set_window (WindowHandle1)
dev_set_window (WindowHandle1)
dev_clear_window ()
*********************************** 我们可以消除源于场景边界的三维边缘(红色显示),以避免场景角落出现额外的匹配。
Text := 'We can eliminate the 3D edges stemming from the boundary of the scene (displayed in red) to avoid the additional matches in the corners of the scene.'
wrap_text (Text, LineLength, TextWrapped)
dev_disp_text (TextWrapped, 'window', 'top', 'left', 'black', 'box', 'false')
* Eliminate 3D edges at the boundary of the scene.
Border := 50
* 将点云图片转换为图像
object_model_3d_to_xyz (XEdges, YEdges, ZEdges, ObjectModel3DEdges, 'from_xyz_map', [], [])
get_image_size (XEdges, WidthMapping, HeightMapping)
select_points_object_model_3d (ObjectModel3DEdges, ['mapping_row','mapping_col'], [Border,Border], [HeightMapping - Border,WidthMapping - Border], ObjectModel3DEdgesWithoutBorder)
* Display results.
visualize_object_model_3d (WindowHandle2, [ObjectModel3DEdgesWithoutBorder,ObjectModel3DEdges], [], VisPose, ['color_0','color_1'], ['green','red'], 'Scene edges with removed edges at the boundary', [], VisInstructions, VisPose)
* 
* Show results of edge-supported surface-based matching when using manipulated 3D edges.
dev_set_window (WindowHandle1)
dev_clear_window ()
* 如果没有场景边界的边缘,在场景的角落里就找不到额外的匹配点。
Text := 'Without the edges at the boundary of the scene, no additional matches are found in the corners of the scene.'
wrap_text (Text, LineLength, TextWrapped)
*您可以以任何方式修改 3D 边缘。要使用修改后的边缘,必须将它们作为 find_surface_model 运算符的通用参数 ('3d_edges/')的值。
dev_disp_text (TextWrapped, 'window', 'top', 'left', 'black', 'box', 'false')
Text := 'You can modify the 3D edges in any way. To use modified edges, they must be given as value of the generic parameter \'3d_edges\' of the operator find_surface_model.'
wrap_text (Text, LineLength, TextWrapped)
dev_disp_text (TextWrapped, 'window', 150, 'left', 'black', 'box', 'false')
* Perform edge-supported surface-based matching.
* 发现模版
find_surface_model (SurfaceModel, ObjectModel3DScene, 0.05, 0.1, MinScore, 'false', ['num_matches','3d_edges'], [5,ObjectModel3DEdgesWithoutBorder], Pose, Score, SurfaceMatchingResult)
* Display results.
rigid_trans_object_model_3d (ObjectModel3DModel, Pose, ObjectModel3DRigidTrans)
visualize_object_model_3d (WindowHandle2, [ObjectModel3DScene,ObjectModel3DEdgesWithoutBorder,ObjectModel3DRigidTrans], [], VisPose, [VisParamNames,'color_1'], [VisParamValues,'green'], 'Matching result with cropped edges', [], VisInstructions, VisPose)
clear_object_model_3d (ObjectModel3DRigidTrans)
* 
* Show how to remove the background plane from the scene.
dev_set_window (WindowHandle1)
dev_clear_window ()
*避免背景平面匹配的更好方法是将背景平面从场景中完全移除。
Text := 'An even better way to avoid matches in the background plane is to completely remove the background plane from the scene.'
wrap_text (Text, LineLength, TextWrapped)
dev_disp_text (TextWrapped, 'window', 'top', 'left', 'black', 'box', 'false')
Text := 'This is sometimes not possible, but if it is, you should do it!'
wrap_text (Text, LineLength, TextWrapped)
dev_disp_text (TextWrapped, 'window', 150, 'left', 'black', 'box', 'false')
* Remove the background plane from the scene.
* 移除背景
select_points_object_model_3d (ObjectModel3DScene, 'point_coord_z', 0.1, 0.73, SceneWithoutBackground)
* Display results.
rigid_trans_object_model_3d (ObjectModel3DModel, Pose, ObjectModel3DRigidTrans)
visualize_object_model_3d (WindowHandle2, [SceneWithoutBackground,ObjectModel3DScene], [], VisPose, ['color_0','color_1','alpha_1'], ['white','red',0.5], 'Scene and removed background', [], VisInstructions, VisPose)
clear_object_model_3d (ObjectModel3DRigidTrans)
dev_set_window (WindowHandle2)
dev_clear_window ()
* 
* Show results of edge-supported surface-based matching when using a scene without the background plane.
dev_set_window (WindowHandle1)
dev_clear_window ()
*在没有场景背景平面的情况下,在场景的角落里找不到额外的匹配结果。此外,如果将背景从场景中移除,匹配速度会明显加快。
Text := 'Without the background plane of the scene, no additional matches are found in the corners of the scene. Furthermore, the matching is significantly faster if the background has been removed from the scene.'
wrap_text (Text, LineLength, TextWrapped)
dev_disp_text (TextWrapped, 'window', 'top', 'left', 'black', 'box', 'false')
dev_disp_text ('Determining speedup...', 'window', 200, 'left', 'black', 'box', 'false')
* Determine speedup.
Num := 5
count_seconds (S1)
for I := 1 to Num by 1find_surface_model (SurfaceModel, ObjectModel3DScene, 0.05, 0.1, MinScore, 'false', 'num_matches', 3, Pose, Score, SurfaceMatchingResult)
endfor
count_seconds (S2)
TimeWithBackground := (S2 - S1) / real(Num) * 1000.0
count_seconds (S1)
for I := 1 to Num by 1find_surface_model (SurfaceModel, SceneWithoutBackground, 0.05, 0.1, MinScore, 'false', 'num_matches', 3, Pose, Score, SurfaceMatchingResult)
endfor
count_seconds (S2)
TimeNoBackground := (S2 - S1) / real(Num) * 1000.0
* 
Text[0] := 'Runtime:'
Text[1] := '  With background:    ' + TimeWithBackground$'4.0f' + ' ms'
Text[2] := '  Without background: ' + TimeNoBackground$'4.0f' + ' ms'
dev_disp_text (Text, 'window', 250, 'left', 'black', 'box', 'false')
* 显示匹配结果
* Display results.
edges_object_model_3d (SceneWithoutBackground, 0.01 * Diameter, [], [], ObjectModel3DEdgesWithoutBackground)
rigid_trans_object_model_3d (ObjectModel3DModel, Pose, ObjectModel3DRigidTrans)
visualize_object_model_3d (WindowHandle2, [SceneWithoutBackground,ObjectModel3DEdgesWithoutBackground,ObjectModel3DRigidTrans], [], VisPose, [VisParamNames,'color_1'], [VisParamValues,'green'], 'Matching result in scene with removed background', [], VisInstructions, VisPose)
clear_object_model_3d (ObjectModel3DRigidTrans)
* 
* Speedup edge-supported surface-based matching by reducing the number of points used for pose refinement.
****************************************姿态细化加快匹配速度
dev_set_window (WindowHandle1)
dev_clear_window ()
*如果搜索场景中的点与物体的大小相比比较密集,也就是说,如果姿态细化必须使用大量的点,就有可能进一步提高速度。
Text := 'Further speedup is possible, if the points in the search scene are dense compared to the size of the object, i.e., if the pose refinement has to use a large number of points.'
wrap_text (Text, LineLength, TextWrapped)
dev_disp_text (TextWrapped, 'window', 'top', 'left', 'black', 'box', 'false')
*可以通过增加通用参数 \'pose_ref_sub_sampling(')来减少用于姿态细化的点数。'
Text := 'The number of points used for the pose refinement can be reduced by increasing the generic parameter \'pose_ref_sub_sampling\'. '
wrap_text (Text, LineLength, TextWrapped)
dev_disp_text (TextWrapped, 'window', 150, 'left', 'black', 'box', 'false')
dev_disp_text ('Determining speedup...', 'window', 270, 'left', 'black', 'box', 'false')
* Determine speedup.
Num := 5
count_seconds (S1)
for I := 1 to Num by 1find_surface_model (SurfaceModel, ObjectModel3DScene, 0.05, 0.1, MinScore, 'false', ['num_matches','pose_ref_sub_sampling'], [3,20], Pose, Score, SurfaceMatchingResult)
endfor
count_seconds (S2)
TimeWithBackgroundPoseRefSubSampling := (S2 - S1) / real(Num) * 1000.0
count_seconds (S1)
for I := 1 to Num by 1find_surface_model (SurfaceModel, SceneWithoutBackground, 0.05, 0.1, MinScore, 'false', ['num_matches','pose_ref_sub_sampling'], [3,20], Pose, Score, SurfaceMatchingResult)
endfor
count_seconds (S2)
TimeNoBackgroundPoseRefSubSampling := (S2 - S1) / real(Num) * 1000.0
* 
Text[0] := 'Runtime:'
Text[1] := '  pose_ref_sub_sampling = 2 (default):'
Text[2] := '    With background:    ' + TimeWithBackground$'4.0f' + ' ms'
Text[3] := '    Without background: ' + TimeNoBackground$'4.0f' + ' ms'
Text[4] := '  pose_ref_sub_sampling = 20:'
Text[5] := '    With background:    ' + TimeWithBackgroundPoseRefSubSampling$'4.0f' + ' ms'
Text[6] := '    Without background: ' + TimeNoBackgroundPoseRefSubSampling$'4.0f' + ' ms'
dev_disp_text (Text, 'window', 300, 'left', 'black', 'box', 'false')
* Display results.
rigid_trans_object_model_3d (ObjectModel3DModel, Pose, ObjectModel3DRigidTrans)
visualize_object_model_3d (WindowHandle2, [SceneWithoutBackground,ObjectModel3DEdgesWithoutBackground,ObjectModel3DRigidTrans], [], VisPose, [VisParamNames,'color_1'], [VisParamValues,'green'], 'Matching result in scene with pose_ref_sub_sampling = 20', [], VisInstructions, VisPose)
clear_object_model_3d (ObjectModel3DRigidTrans)
* 
* Show results of edge-supported surface-based matching with use of image edges.
dev_set_window (WindowHandle1)
dev_clear_window ()
*您甚至可以使用图像数据来改进匹配结果。如果场景的 3D 边缘模糊或扭曲,这一点尤其有用。图像边缘通常更清晰,从而提高了匹配的准确性。
Text := 'You can even use image data to improve the matching results. This is especially helpful if the 3D edges from the scene are blurry or distorted. The typically better defined image edges improve the matching accuracy.'
wrap_text (Text, LineLength, TextWrapped)
dev_disp_text (TextWrapped, 'window', 'top', 'left', 'black', 'box', 'false')
Text := 'To use image edges, use the operator find_surface_model_image.'
wrap_text (Text, LineLength, TextWrapped)
dev_disp_text (TextWrapped, 'window', 200, 'left', 'black', 'box', 'false')
* Perform edge-supported surface-based matching.
set_surface_model_param (SurfaceModel, 'camera_parameter', CameraParam)
set_surface_model_param (SurfaceModel, 'camera_pose', CameraPose)
find_surface_model_image (Image, SurfaceModel, SceneWithoutBackground, 0.05, 0.1, MinScore, 'false', ['num_matches','pose_ref_sub_sampling'], [5,20], Pose, Score, SurfaceMatchingResult)
* Display results.
rigid_trans_object_model_3d (ObjectModel3DModel, Pose, ObjectModel3DRigidTrans)
* Get gray values from image.
object_model_3d_to_xyz (X, Y, Z, SceneWithoutBackground, 'from_xyz_map', [], [])
get_domain (Z, Domain)
get_region_points (Domain, Rows, Columns)
get_grayval (Image, Rows, Columns, AttribValues)
* Set the gray values as attributes of the 3D object model.
set_object_model_3d_attrib_mod (SceneWithoutBackground, '&gray', 'points', AttribValues)
visualize_object_model_3d (WindowHandle2, [SceneWithoutBackground,ObjectModel3DEdgesWithoutBackground,ObjectModel3DRigidTrans], [], VisPose, [VisParamNames,'color_1','color_attrib_0'], [VisParamValues,'green','&gray'], 'Matching result with 2D and 3D edge support', [], VisInstructions, VisPose)
clear_object_model_3d (ObjectModel3DRigidTrans)
* Display results on image.
set_window_param (WindowHandle2, 'flush', 'false')
dev_set_lut ('cubic_root')
dev_set_line_width (3)
dev_set_color ('green')
dev_display (Image)
dev_disp_text ('Matching results projected into the image', 'window', 'top', 'left', 'black', [], [])
gen_empty_obj (AllContours)
for Index := 0 to |Score| - 1 by 1CurrPose := Pose[7 * Index:7 * Index + 6]project_object_model_3d (Contours, ObjectModel3DModel, CameraParam, CurrPose, [], [])concat_obj (AllContours, Contours, AllContours)
endfor
dev_display (AllContours)
dev_set_line_width (1)
flush_buffer (WindowHandle2)
set_window_param (WindowHandle2, 'flush', 'true')
* 
dev_set_window (WindowHandle2)
dev_disp_text ('      End of program      ', 'window', 'bottom', 'right', 'black', [], [])
clear_object_model_3d ([ObjectModel3DModel,ObjectModel3DScene,ObjectModel3DEdges,ObjectModel3DEdgesWithoutBorder,SceneWithoutBackground,ObjectModel3DEdgesWithoutBackground])
clear_surface_model ([SurfaceModel,SurfaceModelWithoutEdgeSupport])
stop ()
* 
dev_set_lut ('default')

Halcon 3D表面匹配

相关文章:

Halcon 3D加快表面匹配速度

文章目录 gen_box_object_model_3d 创建一个代表盒子的 3D 物体模型write_surface_model — 将表面模型写入文件read_surface_model — 将表面模型读取prepare_object_model_3d - 为某个操作准备三维对象模型select_points_object_model_3d - 对 3D 物体模型的属性应用阈值。se…...

Linux系统编程之高级信号处理

概述 在前一篇文章中,我们介绍了signal函数、sigaction函数等基本的信号处理方法。在本篇中,我们将介绍信号处理的一些高级用法,包括:阻塞与解除阻塞、定时器等。 阻塞与解除阻塞 有时候,我们不希望某个信号立即被处理…...

Ollama 本地GUI客户端:为DeepSeek用户量身定制的智能模型管理与交互工具

Ollama 本地GUI客户端:为DeepSeek用户量身定制的智能模型管理与交互工具 相关资源文件已经打包成EXE文件,可双击直接运行程序,且文章末尾已附上相关源码,以供大家学习交流,博主主页还有更多Python相关程序案例&#xf…...

基于SSM的《计算机网络》题库管理系统(源码+lw+部署文档+讲解),源码可白嫖!

摘 要 《计算机网络》题库管理系统是一种新颖的考试管理模式,因为系统是用Java技术进行开发。系统分为三个用户进行登录并操作,分别是管理员、教师和学生。教师在系统后台新增试题和试卷,学生进行在线考试,还能对考生记录、错题…...

对Revit事务机制的一些推测

什么是事务机制 首先,什么是事务机制。软件事务机制是指一种在软件系统中用于管理一系列操作的方法,这些操作要么全部成功完成,要么全部失败,不会出现部分完成的情况。事务机制确保了数据的一致性和完整性,特别是在并…...

软件架构设计:网络基础

一、计算机网络概述 计算机网络的定义 计算机网络是通过通信设备和线路将分散的计算机系统连接起来,实现资源共享和信息传递的系统。 计算机网络的分类 按覆盖范围:局域网(LAN)、城域网(MAN)、广域网&…...

《微软量子芯片:开启量子计算新纪元》:此文为AI自动生成

量子计算的神秘面纱 在科技飞速发展的今天,量子计算作为前沿领域,正逐渐走进大众的视野。它宛如一把神秘的钥匙,有望开启未来科技变革的大门,而微软量子芯片则是这把钥匙上一颗璀璨的明珠。 量子计算,简单来说,是一种遵循量子力学规律调控量子信息单元进行计算的新型计算…...

RocksDB Bloom Filter 如何避免假阳性问题探索

1. 引言:Bloom Filter 的机遇与挑战 Bloom Filter 是数据库系统中广泛使用的概率数据结构,它通过极小的内存开销快速判断一个键是否可能存在于磁盘文件中(如 LSM-Tree 的 SSTable)。然而,其核心缺陷是存在假阳性&…...

SpringBoot+Vue+Mysql苍穹外卖

一.项目介绍 1.项目内容 苍穹外卖是一款为大学学子设计的校园外卖服务软件,旨在提供便捷的食堂外卖送至宿舍的服务。该软件包含系统管理后台和用户端(微信小程序)两部分,支持在线浏览菜品、添加购物车、下单等功能,并…...

网络运维学习笔记 018 HCIA-Datacom综合实验02

文章目录 综合实验2sw3:sw4:gw:core1(sw1):core2(sw2):ISP 综合实验2 sw3: vlan 2 stp mode stp int e0/0/1 port link-type trunk port trunk allow-pass v…...

在 Java 中解析 JSON 数据

例子解析以下JSON数据 {"code":0,"msg":"成功","data": [{ "host":"1068222.com", "port":"", "m_token":"490e20e70e7de5f21a24b14c12a393f6", "categ…...

QT 引入Quazip和Zlib源码工程到项目中,无需编译成库,跨平台,压缩进度

前言 最近在做项目时遇到一个需求,需要将升级的文件压缩成zip,再进行传输; 通过网络调研,有许多方式可以实现,例如QT私有模块的ZipReader、QZipWriter;或者第三方库zlib或者libzip或者quazip等&#xff1…...

C++ 互斥锁的使用

mutex std::mutex 是C标准库中用于线程同步的互斥锁机制,主要用于保护共享资源,避免多个线程同时访问导致的竞态条件。 它提供了以下功能: 加锁(lock):阻塞当前线程,直到获取锁。 解锁&#…...

使用 deepseek实现 go语言,读取文本文件的功能,要求支持 ascii,utf-8 等多种格式自适应

使用 deepseek实现 go语言,读取文本文件的功能,要求支持 ascii,utf-8 等多种格式自适应我要用 chatgpt,也问过,但是比 deepseek 还是差一个级别,具体如下: package mainimport ("bufio&qu…...

车载诊断架构 --- LIN节点路由转发注意事项

我是穿拖鞋的汉子,魔都中坚持长期主义的汽车电子工程师。 老规矩,分享一段喜欢的文字,避免自己成为高知识低文化的工程师: 简单,单纯,喜欢独处,独来独往,不易合同频过着接地气的生活,除了生存温饱问题之外,没有什么过多的欲望,表面看起来很高冷,内心热情,如果你身…...

Eclipse2024中文汉化教程(图文版)

对应Eclipse,部分人需要中文汉化,本章教程,介绍如何对Eclipse进行汉化的具体步骤。 一、汉化前的Eclipse 默认安装Eclipse的时候,默认一般都是English的,我当前版本是使用的是2024-06版本的Eclipse。 二、汉化详细步骤 点击上方菜单选项卡,Hep——Install New Software……...

网络协议相关知识有哪些?

前言 网络协议的基础是OSI和TCP/IP模型,这两个模型是理解协议分层的关键。 正文(仅是个人理解,如有遗漏望海涵) 网络协议是网络中设备间通信的规则和标准,涉及数据传输、路由、错误控制等多个方面。以下是网络协议相关知识的系统梳理: 一、网络协议分层模型 1、OSI七…...

医院安全(不良)事件上报系统源码,基于Laravel8开发,依托其优雅的语法与强大的扩展能力

医院安全(不良)事件上报系统源码 系统定义: 规范医院安全(不良)事件的主动报告,增强风险防范意识,及时发现医院不良事件和安全隐患,将获取的医院安全信息进行分析反馈,…...

【第一节】C++设计模式(创建型模式)-工厂模式

目录 前言 一、面向对象的两类对象创建问题 二、解决问题 三、工厂模式代码示例 四、工厂模式的核心功能 五、工厂模式的应用场景 六、工厂模式的实现与结构 七、工厂模式的优缺点 八、工厂模式的扩展与优化 九、总结 前言 在面向对象系统设计中,开发者常…...

分发糖果(力扣135)

题目说相邻的两个孩子中评分更高的孩子获得的糖果更多,表示我们既要考虑到跟左边的孩子比较,也要考虑右边的孩子,但是我们如果两边一起考虑一定会顾此失彼。这里就引入一个思想:先满足右边大于左边时的糖果分发情况,再…...

爬虫小案例豆瓣电影top250(json格式)

1.json格式(仅供学习参考) import requests, json, jsonpathclass Start(object):# 类实例化时会执行def __init__(self):self.headers {user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.…...

RTSP场景下RTP协议详解及音视频打包全流程

RTSP场景下RTP协议详解及音视频打包全流程 一、RTSP与RTP的关系 RTSP:负责媒体会话控制(DESCRIBE、SETUP、PLAY、PAUSE),通过SDP协商传输参数(端口、编码格式、封装模式)。RTP:实际传输音视频数…...

关于Transparent native-to-ascii conversion

1、功能 自动转换ASCII编码,即在文件系统上,文件的编码格式为ascii编码,在编辑器(idea/pycharm)中,其展现结果为配置的编码格式,仅展现方便阅读 使用UTF-8并勾选自动转换ASCII编码结果&#x…...

万字长文解析:深入理解服务端渲染(SSR)架构与全栈实践指南

一、SSR核心原理深度剖析 1.1 技术定义与演进历程 服务端渲染(Server-Side Rendering)指在服务器端完成页面DOM构建的技术方案。其发展历程可分为三个阶段: 阶段时期典型技术传统SSR2000-2010JSP/PHP现代SSR2015-2020Next.js/Nuxt.js混合渲…...

Spring事务原理 二

在上一篇博文《Spring事务原理 一》中,我们熟悉了Spring声明式事务的AOP原理,以及事务执行的大体流程。 本文中,介绍了Spring事务的核心组件、传播行为的源码实现。下一篇中,我们将结合案例,来讲解实战中有关事务的易…...

SpringAI系列 - ToolCalling篇(二) - 如何设置应用侧工具参数ToolContext(有坑)

目录 一、引言二、集成ToolContext示例步骤1: 在`@Tool`标注的工具方法中集成`ToolConext`参数步骤2:`ChatClient`运行时动态设置`ToolContext`参数三、填坑一、引言 在使用AI大模型的工具调用机制时,工具参数都是由大模型解析用户输入上下文获取的,由大模型提供参数给本地…...

本地部署MindSearch(开源 AI 搜索引擎框架),然后上传到 hugging face的Spaces——L2G6

部署MindSearch到 hugging face Spaces上——L2G6 任务1 在 官方的MindSearch页面 复制Spaces应用到自己的Spaces下,Space 名称中需要包含 MindSearch 关键词,请在必要的步骤以及成功的对话测试结果当中 实现过程如下: 2.1 MindSearch 简…...

MyBatis Plus扩展功能

一、代码生成器 二、逻辑删除 三、枚举处理器 像状态字段我们一般会定义一个枚举,做业务判断的时候就可以直接基于枚举做比较。但是我们数据库采用的是int类型,对应的PO也是Integer。因此业务操作时必须手动把枚举与Integer转换,非常麻烦。 …...

深度学习之自然语言处理CBOW预测及模型的保存

自然语言处理CBOW预测及模型的保存 目录 自然语言处理CBOW预测及模型的保存1 自然语言处理1.1 概念1.2 词向量1.2.1 one-hot编码1.2.2 词嵌入1.2.3 常见的词嵌入模型 2 CBOW预测模型搭建2.1 数据及模型确定2.1.1 数据2.1.2 CBOW模型2.1.3 词嵌入降维 2.2 数据预处理2.3 模型搭建…...

qt项目配置部署

Test项目: 子项目testFileHelper 1.新建一个test项目的子项目:取名testFileHelper 2.编写测试用例 3.pro文件中引入qosbrowser 4.引入测试对象的cpp和头文件 2.在项目中引入资源文件testfile.txt,在其中输入abc 实现thrid目录复用 移动thrid 将thrild目录统一放在章…...