halcon三维点云数据处理(七)find_shape_model_3d_recompute_score

目录

一、find_shape_model_3d_recompute_score例程代码

csharp 复制代码
gen_cam_par_area_scan_division (0.01, 0, 7e-6, 7e-6, 320, 240, 640, 480, CamParam)
get_cam_par_data (CamParam, 'image_width', Width)
get_cam_par_data (CamParam, 'image_height', Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_set_part (0, 0, Height - 1, Width - 1)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_update_off ()
* 
* Generate a cube
X := [-1, -1, 1, 1, -1, -1, 1, 1]
Y := [1, -1, -1, 1, 1, -1, -1, 1]
Z := [-1, -1, -1, -1, 1, 1, 1, 1]
Polygons := [4, 0, 1, 2, 3, 4, 4, 5, 6, 7, 4, 0, 1, 5, 4, 4, 3, 2, 6, 7, 4, 0, 3, 7, 4, 4, 1, 2, 6, 5]
gen_object_model_3d_from_points (X, Y, Z, ObjectModel3DID)
set_object_model_3d_attrib_mod (ObjectModel3DID, 'polygons', [], Polygons)
* 
* Prepare the 3D object model for matching
prepare_object_model_3d (ObjectModel3DID, 'shape_based_matching_3d', 'true', [], [])
* 
* Display the 3D object model
disp_object_model_3d_safe (WindowHandle, ObjectModel3DID, CamParam, [0, 0, 11, 30, 40, 0, 0], [], [])
disp_message (WindowHandle, '3D Object Model of a Cube', 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
* 
* Generate the 3D shape model
create_cube_shape_model_3d (WindowHandle, ObjectModel3DID, CamParam, ShapeModel3DID)
* 
Scores1 := []
Scores2 := []
Times1 := []
Times2 := []
Longitudes := []
Latitude := rad(45)
Distance := 11.5
dev_set_color ('green')
dev_set_line_width (2)
for Longitude := rad(30) to rad(60) by rad(0.25)
    convert_point_3d_spher_to_cart (Longitude, Latitude, Distance, '-y', '-z', CamX, CamY, CamZ)
    create_cam_pose_look_at_point (CamX, CamY, CamZ, 0, 0, 0, '-y', 0, CamPose)
    * Prevent flickering
    set_system ('flush_graphic', 'false')
    * 
    * Generate an artificial image of the cube
    project_cube_image (Image, CamPose, CamParam, X, Y, Z, Polygons)
    * 
    * Find the cube by using 3D shape-based matching
    * ('recompute_score' = 'false')
    count_seconds (Seconds1)
    find_shape_model_3d (Image, ShapeModel3DID, 0.7, 0.9, 0, [], [], Pose1, CovPose1, Score1)
    count_seconds (Seconds2)
    Time1 := (Seconds2 - Seconds1) * 1000.0
    * Find the cube by using 3D shape-based matching
    * ('recompute_score' = 'true')
    count_seconds (Seconds1)
    find_shape_model_3d (Image, ShapeModel3DID, 0.7, 0.9, 0, 'recompute_score', 'true', Pose2, CovPose2, Score2)
    count_seconds (Seconds2)
    Time2 := (Seconds2 - Seconds1) * 1000.0
    * 
    * Display the matching result
    dev_display (Image)
    if (|Score1| == 1 and |Score2| == 1)
        * Display the match
        project_shape_model_3d (ModelContours, ShapeModel3DID, CamParam, Pose1, 'true', rad(30))
        dev_display (ModelContours)
        * Display the matching time and score
        disp_message (WindowHandle, 'Matching at Longitude: ' + deg(Longitude)$'3.1f' + ' deg (from 30 to 60 deg)', 'window', 12, 12, 'white', 'false')
        gen_matching_result_message (Time1, Time2, Score1, Score2, Message)
        disp_message (WindowHandle, Message, 'window', 420, 12, ['white', 'yellow', 'green'], 'false')
        * Remember the score values
        Longitudes := [Longitudes,deg(Longitude)]
        Scores1 := [Scores1,Score1]
        Scores2 := [Scores2,Score2]
        Times1 := [Times1,Time1]
        Times2 := [Times2,Time2]
    endif
    * Prevent flickering
    set_system ('flush_graphic', 'true')
    * Show what we painted in the loop by drawing a invisible line
    disp_line (WindowHandle, -1, -1, -1, -1)
endfor
* 
* Display the score values
dev_clear_window ()
Title := ['\'recompute_score\'=\'false\'', '\'recompute_score\'=\'true\'']
Colors := ['yellow', 'green']
plot_tuple (WindowHandle, Longitudes, [Scores1,Scores2], 'Longitude [deg]', 'Matching score', Colors, ['ticks_x', 'ticks_y', 'end_y'], [6, .01, 1])
disp_message (WindowHandle, Title, 'window', 12, 350, Colors, 'false')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
dev_clear_window ()
plot_tuple (WindowHandle, Longitudes, [Times1,Times2], 'Longitude [deg]', 'Matching time [ms]', Colors, 'ticks_x', 6)
disp_message (WindowHandle, Title, 'window', 12, 350, Colors, 'false')

二、set_object_model_3d_attrib_mod函数

csharp 复制代码
set_object_model_3d_attrib_mod( : : ObjectModel3D, AttribName, AttachExtAttribTo, AttribValues : )

set_object_model_3d_attrib_mod 函数将给定的 AttribName 中的标准属性或扩展属性设置为 AttribValues 中的值。set_object_model_3d_attrib_mod 与 set_object_model_3d_attrib 函数相同,不同之处在于它不会创建新的 3D 对象模型,而是修改给定的对象模型。通过设置参数 AttachExtAttribTo,可以将扩展属性的值附加到 3D 对象模型已有的标准属性上。对于标准属性,AttachExtAttribTo 参数将被忽略。

如果在 AttribName 中的属性不存在,则在可能的情况下创建它们。如果已存在的属性被设置,那么 AttribValues 的长度必须与现有的属性值长度相匹配。在这种情况下,现有的属性值将被替换。如果使用 AttachExtAttribTo 将扩展属性附加到已存在的标准属性上,那么 AttribValues 的长度必须与现有的属性值长度相匹配

'polygons':

上面的程序中设置的'polygons',我个人认为是很难理解的。

csharp 复制代码
Polygons := [4, 0, 1, 2, 3, 4, 4, 5, 6, 7, 4, 0, 1, 5, 4, 4, 3, 2, 6, 7, 4, 0, 3, 7, 4, 4, 1, 2, 6, 5]
set_object_model_3d_attrib_mod (ObjectModel3DID, 'polygons', [], Polygons)

这里的Polygons 是点数+ 点的索引。4个点(0,1,2,3),接下来的 4个点(4,5,6,7),这里的Polygons 表示的是正方体的6个面

三、prepare_object_model_3d 函数

为某一操作准备三维对象模型

它计算操作所需的值并将其存储在ObjectModel3D中,从而加快了后续操作。没有必要调用prepare_object_model_3d。但是,如果要多次使用3D对象模型进行相同的操作,则可以更快。

csharp 复制代码
prepare_object_model_3d( : : ObjectModel3D, Purpose, OverwriteData, GenParamName, GenParamValue : )

prepare_object_model_3d (ObjectModel3DID, 'shape_based_matching_3d', 'true', [], [])

Purpose: 'shape_based_matching_3d', 'segmentation', 'distance_computation', 'gen_xyz_mapping'

四、create_cube_shape_model_3d函数

生成3D形状模型,这是一个自定义函数

五、获得CamPose

在球坐标系上选取一点作为相机位置,转换为笛卡尔坐标。再通过create_cam_pose_look_at_point 函数确定相机位姿。

csharp 复制代码
convert_point_3d_spher_to_cart (Longitude, Latitude, Distance, '-y', '-z', CamX, CamY, CamZ)
create_cam_pose_look_at_point (CamX, CamY, CamZ, 0, 0, 0, '-y', 0, CamPose)

六、project_cube_image函数

把立方体的三个面,投影到图像上。

七、find_shape_model_3d函数

在图像中找到3D形状模型的最佳匹配

八、project_shape_model_3d函数

将三维形状模型的边缘投影到图像坐标中。

相关推荐
17´43 分钟前
使用QT+OpenCV+C++完成一个简单的图像处理工具
c++·图像处理·qt·opencv
布兰妮甜3 小时前
Three.js 渲染技术:打造逼真3D体验的幕后功臣
javascript·3d·three.js·幕后
思考实践4 小时前
3D Object Detection和6D Pose Estimation有什么异同?
目标检测·计算机视觉·3d
jndingxin4 小时前
OpenCV相机标定与3D重建(46)将三维空间中的点投影到二维图像平面上函数projectPoints()的使用
opencv·3d
我命由我123455 小时前
CesiumJS 案例 P34:场景视图(3D 视图、2D 视图)
前端·javascript·3d·前端框架·html·html5·js
敢敢のwings5 小时前
3D高斯点云CUDA版本数据制作与demo运行
3d
机智的小神仙儿8 小时前
基于ResNet的CIFAR-10分类实现与分析
图像处理·人工智能·数据挖掘
青春~飞鸟8 小时前
丢帧常见的几种处理方法
图像处理·数码相机·计算机视觉
Struart_R9 小时前
HunyuanVideo: A Systematic Framework For LargeVideo Generative Models 论文解读
人工智能·深度学习·计算机视觉·3d·transformer·扩散模型·视频生成
jndingxin13 小时前
OpenCV相机标定与3D重建(49)将视差图(disparity map)重投影到三维空间中函数reprojectImageTo3D()的使用
3d