Halcon机器视觉论坛

 找回密码
 会员注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 4392|回复: 3
收起左侧

Halcon自带三维物体定位技术

[复制链接]
  • TA的每日心情
    耍酷
    昨天 16:46
  • 签到天数: 636 天

    连续签到: 23 天

    [LV.9]以坛为家II

    353

    主题

    1357

    帖子

    5261

    积分

    Rank: 9

    积分
    5261

    突出贡献优秀版主荣誉管理论坛元老切换助手验证会员最佳新人

    发表于 2016-11-22 13:51:33 | 显示全部楼层 |阅读模式

    管理员 |主题 353|帖子 1357|积分 5261

    51Halcon诚邀您的加入,专注于机器视觉开发与应用技术,我们一直都在努力!

    您需要 登录 才可以下载或查看,没有帐号?会员注册

    x
    1. * This example program shows how to use HALCON's 3D-Matching
    2. * to find the 3D pose of clamps that exhibit a 6 degree of freedom
    3. * motion.
    4. * If the 3D shape model should be re-generated within a new
    5. * pose range ReCreateShapeModel3D must be set to true.
    6. * In this case inspect_object_model_3d can be used to determine
    7. * the desired pose range in which the 3D shape model is to be
    8. * created. In all cases, however, inspect_object_model_3d can
    9. * be used to visualize the 3D object model.
    10. *
    11. ReCreateShapeModel3D := false
    12. * ReCreateShapeModel3D := true
    13. *
    14. * Set the camera parameters (can be obtained by using calibrate_cameras)
    15. gen_cam_par_area_scan_division (0.01221, -2791, 7.3958e-6, 7.4e-6, 308.21, 245.92, 640, 480, CamParam)
    16. *
    17. get_cam_par_data (CamParam, 'image_width', Width)
    18. get_cam_par_data (CamParam, 'image_height', Height)
    19. dev_close_window ()
    20. dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
    21. set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
    22. dev_update_off ()
    23. *
    24. * Read the object model from a DXF file
    25. read_object_model_3d ('clamp_sloped', 'mm', [], [], ObjectModel3DID, DxfStatus)
    26. * Prepare the object model for the use within the 3d shape-based matching
    27. prepare_object_model_3d (ObjectModel3DID, 'shape_based_matching_3d', 'true', [], [])
    28. *
    29. * Read some example images that can be passed to inspect_object_model_3d
    30. gen_empty_obj (Images)
    31. for Index := 1 to 3 by 1
    32.     read_image (Image, 'clamp_sloped/clamp_sloped_' + Index效果:

    33. 02')
    34.     concat_obj (Images, Image, Images)
    35. endfor
    36. *
    37. * Inspect the 3D object model and specify the desired pose range
    38. * in which the 3D shape model is to be created
    39. inspect_object_model_3d (Images, ObjectModel3DID, CamParam, RefRotX, RefRotY, RefRotZ, LongitudeMin, LongitudeMax, LatitudeMin, LatitudeMax, CamRollMin, CamRollMax, DistMin, DistMax, MinFaceAngle)
    40. *
    41. dev_clear_window ()
    42. if (ReCreateShapeModel3D)
    43.     * If desired re-create the 3D shape model. Note that this may take
    44.     * several minutes dependent on the hardware and the pose range.
    45.     Message := 'Creating the 3D shape model (may take several minutes) ...'
    46.     disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
    47.     create_shape_model_3d (ObjectModel3DID, CamParam, RefRotX, RefRotY, RefRotZ, 'gba', LongitudeMin, LongitudeMax, LatitudeMin, LatitudeMax, 0, rad(360), DistMin, DistMax, 10, 'min_face_angle', MinFaceAngle, ShapeModel3DID)
    48.     write_shape_model_3d (ShapeModel3DID, 'clamp_sloped_user.sm3')
    49. else
    50.     * If desired read the 3D shape model from disk
    51.     Message := 'Reading the 3D shape model file from disk ...'
    52.     disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
    53.     dev_set_check ('~give_error')
    54.     dev_error_var (ErrorVar, 1)
    55.     read_shape_model_3d ('clamp_sloped_35.sm3', ShapeModel3DID)
    56.     Error := ErrorVar
    57.     dev_set_check ('give_error')
    58.     if (Error != H_MSG_TRUE)
    59.         * Create the 3D shape model if it is not available on disk
    60.         Message := 'Reading the 3D shape model file from disk ... not found!'
    61.         Message[1] := 'Creating the 3D shape model (may take several minutes) ...'
    62.         disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
    63.         create_shape_model_3d (ObjectModel3DID, CamParam, rad(180), 0, rad(90), 'gba', -rad(35), rad(35), -rad(35), rad(35), 0, rad(360), 0.2, 0.25, 10, [], [], ShapeModel3DID)
    64.         write_shape_model_3d (ShapeModel3DID, 'clamp_sloped_35.sm3')
    65.     endif
    66.     * Uncomment the following line of code if the user-generated
    67.     * model is to be used
    68. *     read_shape_model_3d ('clamp_sloped_user.sm3', ShapeModel3DID)
    69. endif
    70. *
    71. * After creating the 3D shape model we do not longer need
    72. * the 3D object model.
    73. clear_object_model_3d (ObjectModel3DID)
    74. *
    75. dev_set_line_width (2)
    76. *
    77. * Find instances of a 3D shape model in some run-time images
    78. for ImageNo := 1 to 35 by 1
    79.     read_image (Image, 'clamp_sloped/clamp_sloped_' + ImageNo效果:

    80. 02')
    81.     dev_display (Image)
    82.     count_seconds (Seconds1)
    83.     * Find up to two instances of the 3D shape model
    84.     find_shape_model_3d (Image, ShapeModel3DID, 0.7, 0.9, 5, ['num_matches','pose_refinement'], [2,'least_squares_very_high'], Pose, CovPose, Score)
    85.     count_seconds (Seconds2)
    86.     Time := Seconds2 - Seconds1
    87.     Message := |Score| + ' Match(es) found in ' + Time效果:

    88. 4.3f' + ' s'
    89.     disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
    90.     Time := Seconds2 - Seconds1
    91.     for I := 0 to |Score| - 1 by 1
    92.         PoseI := Pose[I * 7:I * 7 + 6]
    93.         CovPoseI := CovPose[I * 6:I * 6 + 5]
    94.         ScoreI := Score[I]
    95.         * Visualize the found matches in the image by
    96.         * - projecting the 3D shape model with the pose of the match
    97.         project_shape_model_3d (ModelContours, ShapeModel3DID, CamParam, PoseI, 'true', 0.523599)
    98.         dev_set_color ('blue')
    99.         dev_display (ModelContours)
    100.         * - projecting the coordinate system of the 3D object model
    101.         dev_set_color ('coral')
    102.         disp_3d_coord_system (WindowHandle, CamParam, PoseI, 0.015)
    103.         * Display the parameters of the found pose
    104.         dev_set_color ('magenta')
    105.         display_match_pose (ShapeModel3DID, PoseI, WindowHandle)
    106.     endfor
    107.     disp_continue_message (WindowHandle, 'black', 'true')
    108.     stop ()
    109. endfor
    110. *
    111. Message := 'Program terminated. Press \'Run\' to clear the 3D shape model.'
    112. disp_message (WindowHandle, Message, 'window', Height - 30, 12, 'black', 'true')
    113. *
    114. stop ()
    115. * Free the 3D shape model if it is not longer needed
    116. clear_shape_model_3d (ShapeModel3DID)
    117. dev_update_on ()
    复制代码

    效果:
    QQ截图20161122135013.png
    QQ截图20161122135007.png
    QQ截图20161122134957.png

    通过对目标进行360度建立模型,即可定位物体任意位置,对机械手来说定位是很方便的!

    无效附件更新 权限提升操作 删帖申请 举报以及其他需要帮助请加入QQ群:214663141 广告位招商 有意者联系
  • TA的每日心情
    害羞
    2017-11-1 22:30
  • 签到天数: 3 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    2

    主题

    12

    帖子

    50

    积分

    Rank: 1

    积分
    50
    发表于 2017-11-1 22:56:33 | 显示全部楼层

    试用员工 |主题 2|帖子 12|积分 50

    好帖子啊。请问这个用单目相机能定位到吗

    发帖求助前要善用论坛搜索功能,那里可能会有你要找的答案;

    如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子分类或者标题前面加上【已解决】

    回报帮助你解决问题的坛友,右下角【免费评分】赠与对方视觉币和热心值,伸手党遭人唾弃,做一个热心并受欢迎的人!

    您需要登录后才可以回帖 会员登录 | 会员注册

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    Halcon鸟叔机器视觉1鸟叔机器视觉 | 51Halcon官方客服咨询官方客服咨询 | Halcon切换助手使用反馈切换助手使用反馈 | 51Halcon论坛管理团队论坛管理团队

    申请友链| 小黑屋| 手机版| Archiver| Halcon机器视觉论坛  

    粤ICP备15095995号-2 粤公网安备44030602000670号

    Powered by Discuz! X3.4 Licensed© 2015-2019 Comsenz Inc.

    快速回复 返回顶部 返回列表