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
相关推荐
lingling00914 小时前
结构光相机:重塑工业自动化的“智慧之眼”,驱动智能制造新未来
数码相机
哈市雪花1 天前
相机:Camera原理讲解(使用OpenGL+QT开发三维CAD)
qt·3d·交互·相机·图形学·opengl·视角
啊有礼貌1 天前
【第三章】摄影测量学
数码相机·空中三角测量·摄影测量·倾斜测量
zhongqu_3dnest1 天前
3D建模公司的能力与技术
数码相机·3d·虚拟现实·vr制作公司·3d建模公司
埃菲尔铁塔_CV算法1 天前
基于 TOF 图像高频信息恢复 RGB 图像的原理、应用与实现
人工智能·深度学习·数码相机·算法·目标检测·计算机视觉
syncon121 天前
手机屏色斑缺陷修复及相关液晶线路激光修复原理
科技·3d·制造
九班长1 天前
Golang服务端处理Unity 3D游戏地图与碰撞的详细实现
3d·unity·golang
温轻舟2 天前
3D词云图
前端·javascript·3d·交互·词云图·温轻舟
在下胡三汉2 天前
粗略地看一下 glTF 2.0 的所有标准属性(顺便说一下,还有 .glb 的结构)
3d
zhongqu_3dnest2 天前
3D可视化:开启多维洞察新时代
3d·3d建模·空间计算·3d可视化·三维空间·沉浸式体验