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
相关推荐
k4m7v2pz14 小时前
Bevy 0.18.1 雨雪天气粒子系统排障实录:四个“想当然“如何让 3D/2D 粒子全部不可见
3d·游戏开发·3d渲染·bevy·天气粒子·2d渲染
戴西软件15 小时前
戴西iDWS.3DViz Suite数据轻量化可视化软件,从传统桌面软件向云端协同的重大突破
大数据·运维·网络·人工智能·机器学习·3d
Jmyd012315 小时前
实训室的 3D 模型涉及肖像文物,数据安全与合规怎么做?
安全·3d·数据安全·虚拟实训
AI视觉网奇1 天前
3d子部件高亮选中
开发语言·javascript·3d
浪里镖客1 天前
RM65B睿尔曼机械臂与realsense d4354i相机眼在手外的手眼标定
数码相机
我爱cope1 天前
【计算机网络 | 网络层12:SDN:控制平面与数据平面分离意味着什么?】
网络·学习·计算机网络·平面
长江后浪博客1 天前
陶瓷盘UV喷墨印刷中的Z轴高度测量与防碰撞技术方案
数码相机·uv·陶瓷盘uv打印·uv喷墨印刷·z轴测高·喷头防碰撞·激光位移传感器
我才是银古1 天前
当 360° 全景遇上真实地图:Vue 3 实现全景-地图双向联动的工程实践
3d·vue3·360影像
做cv的小昊2 天前
结合代码读3DGS&世界模型论文(3)——3DGS & 世界模型新工作GaussianDream论文及代码解读
3d
lilian2333 天前
HarmonyOS 7 新特性(十三)|3DGS 模型加载、交互与性能回退
3d·交互·harmonyos