Halcon 3D平面相切案例

文章目录


c 复制代码
* ********************************************************************
* This program shows how to calculate the intersection between a
* 3D object model and a plane.
* The intersection is calculated with the operator
* intersect_plane_object_model.
* The result of the intersection is a set of polylines.
* ********************************************************************
* 
* Read 3D object model
Files := ['bmc_mini','glass_mug']
* 
* Prepare visualization
dev_update_off ()
dev_close_window ()
* 为扫描相机设置参数
gen_cam_par_area_scan_division (0.01, 0, 7e-6, 7e-6, 240, 180, 480, 360, CamParam)
get_cam_par_data (CamParam, 'image_width', ImageWidth)
get_cam_par_data (CamParam, 'image_height', ImageHeight)
dev_open_window (0, 0, ImageWidth, ImageHeight, 'black', WindowHandle1)
set_display_font (WindowHandle1, 14, 'mono', 'true', 'false')
dev_open_window (0, ImageWidth + 12, ImageWidth, ImageHeight, 'black', WindowHandle2)
set_display_font (WindowHandle2, 14, 'mono', 'true', 'false')
dev_open_window (0, ImageWidth , ImageWidth, ImageHeight, 'black', WindowHandle3)
set_display_font (WindowHandle3, 14, 'mono', 'true', 'false')
* Poses for car object
* 设置位姿
create_pose (0.05, 0.10, 1.2, 181.4, 30.6, 359.0, 'Rp+T', 'gba', 'point', VisualizationPose)
create_pose (0.12, 0.08, 1.2, 180.0, 90.0, 0.0, 'Rp+T', 'gba', 'point', PoseConnected)
create_pose (0, 0, 0, 0, 90, 0, 'Rp+T', 'gba', 'point', CutPlanePose)
Border := 0.03
* Poses for mug object
* 显示位姿
VisualizationPose := [VisualizationPose,6.5e-005,-0.15e-3,8.1e-3,120.0,0.0,30.0,0]
* 切面位姿
CutPlanePose := [CutPlanePose,0,0,0,70,0,0,0]
* 分割切面位姿
PoseConnected := [PoseConnected,0.0,-0.1e-3,6.0e-3,90.0,0.0,0.0,0]
Border := [Border,0.0003]
* 
GenParamName := ['color_0','attribute_0','disp_pose_0','light_position']
GenParamValue := ['green','faces','true','0.0 0.0 100.0 1.0']
GenParamName := [GenParamName,'color_1','disp_pose_1','alpha']
GenParamValue := [GenParamValue,'red','false',.5]
ColorSytle := ['colored','color']
ColorValue := [12,'green']
* 
* Compute the interection of a 3d object model with a plane
* successively with two different Object models.
* 计算三维物体模型与平面的垂直度
* 连续使用两个不同的对象模型。
for Index := 0 to |Files| - 1 by 1
    * 
    * Read a 3d object model
    * 读取3D 模型
    read_object_model_3d (Files[Index], 'mm', [], [], ObjectModel3D, Status)
    visualize_object_model_3d(WindowHandle3, ObjectModel3D, [], [], [], [], [], [], [], PoseOut)
    * 
    * Compute the intersection of the object with the plane
    * and calculate the connected components.
    CurrentCutPlanePose := CutPlanePose[Index * 7:Index * 7 + 6]
    count_seconds (Seconds)
    * 计算相交平面
    intersect_plane_object_model_3d (ObjectModel3D, CurrentCutPlanePose, ObjectModel3DIntersection)
    *相交平面显示
    visualize_object_model_3d(WindowHandle3, ObjectModel3DIntersection, [], PoseOut, [], [], [], [], [], PoseOut1)
    count_seconds (Seconds1)
    connection_object_model_3d (ObjectModel3DIntersection, 'lines', 1, ObjectModel3DConnected)
    * 
    * Display results
    * 显示结果
    * Calculate plane extents for visualization
    * 仿射运算
    pose_invert (CurrentCutPlanePose, PoseInvert)
    rigid_trans_object_model_3d (ObjectModel3DIntersection, PoseInvert, ObjectModel3DRigidTrans)
    * 获取3D模型参数
    get_object_model_3d_params (ObjectModel3DRigidTrans, 'bounding_box1', Param1)
    X := [Param1[0] - Border[Index],Param1[0] - Border[Index],Param1[3] + Border[Index],Param1[3] + Border[Index]]
    Y := [Param1[1] - Border[Index],Param1[4] + Border[Index],Param1[4] + Border[Index],Param1[1] - Border[Index]]
    * Generate plane to visualize the intersecting plane
    * 产生相交的平面
    gen_plane_object_model_3d (CurrentCutPlanePose, X, Y, ObjectModel3DPlane)
    * Visualize the scene
    Message := ['Compute the intersection','of the object with the plane']
    disp_object_model_3d_safe (WindowHandle1, [ObjectModel3D,ObjectModel3DPlane], CamParam, VisualizationPose[Index * 7:Index * 7 + 6], GenParamName, GenParamValue)
    disp_message (WindowHandle1, Message, 'window', 12, 12, 'white', 'false')
    * Display the intersection of the object with the plane
    get_object_model_3d_params (ObjectModel3DIntersection, 'num_points', NumPoints)
    if (NumPoints > 0)
        disp_object_model_3d_safe (WindowHandle2, ObjectModel3DConnected, CamParam, PoseConnected[Index * 7:Index * 7 + 6], ['disp_lines',ColorSytle[Index]], ['true',ColorValue[Index]])
        disp_message (WindowHandle2, 'Runtime = ' + ((Seconds1 - Seconds) * 1e3)$'.3' + ' ms', 'window', 12, 12, 'white', 'false')
    else
        Message := 'The intersection of the object with the plane is empty!'
        disp_message (WindowHandle1, Message, 'window', 12, 12, 'white', 'false')
    endif
    * 
    * It is also possible to project the resulting 3D lines into the
    * intersection plane and to convert these planar lines into XLD
    * contours.
    * 还可以将生成的三维线投影到
    * 将这些平面线段转换为 XLD
    * 轮廓线。
    project_object_model_3d_lines_to_contour_xld (Intersection, CurrentCutPlanePose, ObjectModel3DIntersection)
    * Depending on the scale and position of the 3D object, a
    * transformation of the contours might be required for a suitable
    * visualization. The transformation parameters are determinde based
    * on the extent of the intersection contours.
    * 根据三维物体的比例和位置,可能需要对轮廓进行变换,以获得合适的效果。
    * 可能需要对轮廓线进行变换,以获得合适的
    * 可视化。变换参数根据
    * 根据交叉轮廓的范围来确定变换参数。
    determine_transformation_parameters (Intersection, ImageHeight, ImageWidth, 0.1, HomMat2D)
    affine_trans_contour_xld (Intersection, ContoursAffineTrans, HomMat2D)
    * 
    if (Index < |Files| - 1)
        disp_continue_message (WindowHandle2, 'black', 'true')
        stop ()
    endif
    * Clean up memory
    clear_object_model_3d ([ObjectModel3D,ObjectModel3DPlane,ObjectModel3DIntersection,ObjectModel3DRigidTrans,ObjectModel3DConnected])
endfor
相关推荐
越甲八千6 小时前
单个相机矫正畸变
数码相机
LeapMay1 天前
3D Gaussian Splatting代码详解(一):模型训练、数据加载
人工智能·深度学习·3d
LeapMay1 天前
3D Gaussian Splatting 入门
计算机视觉·3d
xhload3d1 天前
掌控物体运动艺术:图扑 Easing 函数实践应用
大数据·3d·智慧城市·html5·webgl·数字孪生·可视化·数据可视化·工业互联网·轻量化·demo·hightopo·大屏展示·图形组件
STRANGEX-031 天前
深度学习案例:带有一个隐藏层的平面数据分类
深度学习·平面·分类
贵州晓智信息科技1 天前
Three.js Shader 与自定义材质—深入理解与应用
开发语言·javascript·3d·材质
Extraovo1 天前
利用 Direct3D 绘制几何体—8.光栅器状态
c++·笔记·学习·3d
Extraovo1 天前
利用 Direct3D 绘制几何体—10.几何图形辅助结构体
c++·笔记·学习·3d
dongdonglele5212 天前
自动驾驶-传感器简述
人工智能·数码相机·自动驾驶