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
相关推荐
十年一梦实验室7 小时前
【C++】sophus : rxso3.hpp 实现了 3D 空间中的旋转和缩放操作的 RxSO3 类 (二十一)
开发语言·c++·人工智能·算法·3d
CES_Asia7 小时前
工信部“人工智能+”制造行动点亮CES Asia 2025
人工智能·科技·数码相机·制造·智能音箱·智能手表
逆旅行天涯9 小时前
【Threejs】从零开始(六)--GUI调试开发3D效果
前端·javascript·3d
mirrornan1 天前
3D和AR技术在电商行业的应用有哪些?
3d·ar·3d建模·3d模型·三维建模
工业3D_大熊1 天前
3D开发工具HOOPS助力造船业加速设计与数字化转型
3d
zaf赵1 天前
3D 高斯溅射 (Gaussian Splatting)技术,一种实现超写实、高效渲染的突破性技术
3d
只待花开1 天前
ROS2 python编写 intel realsense D405相机节点通过launch.py启动多个相机并发送图像话题,基于pyrealsense2库
数码相机
前端Hardy1 天前
HTML&CSS:酷炫的3D开关控件
前端·javascript·css·3d·html
KeyPan1 天前
【ORB-SLAM3:相机针孔模型和相机K8模型】
数码相机
千穹凌帝2 天前
基于深度学习多图像融合的屏幕缺陷检测方案
人工智能·深度学习·数码相机