设置首页收藏本站在线聊天
授权版本:2024_09
开启左侧

[HALCON例程] 超远心镜头成像的视觉处理

[复制链接]
绝地武士 发表于 2024-8-23 20:45:40 | 显示全部楼层 |阅读模式
超远心镜头允许以单个图像同时完成物体的顶部和侧面成像(超广角)功能。
微信截图_20240823203957.jpg
(左)使用常规镜头检查的小瓶的侧视图。(中)使用超心镜头的顶视图。(右)在相机校准和映射后,标签的展开表面。

成像模型如下:
微信截图_20240823203945.jpg
代码:
  1. *
  2. * This example demonstrates how to calibrate a camera
  3. * with a hypercentric lens and how to unroll the label of a bottle,
  4. * which can be used to perform various 360 degree inspection tasks.
  5. *
  6. * Prepare window.
  7. dev_close_window ()
  8. dev_open_window (0, 0, 700, 700, 'black', WindowHandle)
  9. set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
  10. dev_update_off ()
  11. *
  12. * 1. Calibrate the camera (offline).
  13. *
  14. * Specify the calibration object.
  15. CalTabName := 'calplate_40mm.cpd'
  16. * Specify the initial camera parameters.
  17. ImageWidth := 1970
  18. ImageHeight := 1970
  19. gen_cam_par_area_scan_hypercentric_polynomial (0.008, 0, 0, 0, 0, 0, 3.1e-006, 3.1e-006, ImageWidth / 2, ImageHeight / 2, ImageWidth, ImageHeight, CameraParamStart)
  20. * Create a calibration data model.
  21. create_calib_data ('calibration_object', 1, 1, CalibDataID)
  22. set_calib_data_cam_param (CalibDataID, 0, [], CameraParamStart)
  23. set_calib_data_calib_object (CalibDataID, 0, CalTabName)
  24. *
  25. get_window_param (WindowHandle, 'flush', Flush)
  26. set_window_param (WindowHandle, 'flush', 'false')
  27. for J := 1 to 25 by 1
  28.     * Read the calibration image.
  29.     read_image (Image, 'calib/calib_hypercentric_' + J$'02')
  30.     * Find the calibration object in the image.
  31.     find_calib_object (Image, CalibDataID, 0, 0, J, [], [])
  32.     * Visualize the extracted marks.
  33.     get_calib_data_observ_contours (Ellipses, CalibDataID, 'marks', 0, 0, J)
  34.     dev_display (Image)
  35.     dev_set_color ('green')
  36.     dev_display (Ellipses)
  37.     dev_disp_text ('Calibration image ' + J + ' (of 25) and extracted marks', 'window', 'top', 'left', 'black', [], [])
  38.     flush_buffer (WindowHandle)
  39. endfor
  40. set_window_param (WindowHandle, 'flush', Flush)
  41. * Perform the camera calibration.
  42. calibrate_cameras (CalibDataID, Error)
  43. * Query the calibrated camera parameters.
  44. get_calib_data (CalibDataID, 'camera', 0, 'params_labels', CameraParamLabels)
  45. get_calib_data (CalibDataID, 'camera', 0, 'params', CameraParam)
  46. * Display the camera parameters.
  47. display_camera_parameters (CameraParamStart, CameraParam, Error, CameraParamLabels$'-5', WindowHandle)
  48. dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
  49. stop ()
  50. *
  51. * 2. Generate a map that can be used to unroll the surface
  52. *    of a cylindrical object (offline).
  53. *
  54. read_image (Image, 'bottle_label/eye_drops_vial_hypercentric')
  55. dev_display (Image)
  56. dev_disp_text ('Top view of a vial with eye drops\nacquired with a hypercentric lens.', 'window', 'top', 'left', 'black', [], [])
  57. dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
  58. stop ()
  59. * Specify the radius of the cylindrical vial at its base
  60. * and at its circular screw cap on top.
  61. VialRadiusBase := 0.0112
  62. VialRadiusTop := 0.0034
  63. * Determine the pose of the vial.
  64. get_vial_pose (Image, CameraParam, VialRadiusBase, VialRadiusTop, WindowHandle, VialBase, VialAxis)
  65. stop ()
  66. * Create a map that unrolls the labeled surface of the vial.
  67. * Specify the range along the cylinder axis that should be unrolled.
  68. * CylinderZStart = 0 and CylinderZEnd = 0.026
  69. * means that the vial is unrolled from its circular bottom
  70. * up to a height of 2.6 centimeters.
  71. CylinderZStart := 0.0
  72. CylinderZEnd := 0.026
  73. CylinderUnrollAngleStart := rad(40)
  74. MapWidth := 1500
  75. MapHeight := 500
  76. gen_cylinder_unrolling_map (Map, CameraParam, VialBase, VialAxis, VialRadiusBase, CylinderZStart, CylinderZEnd, CylinderUnrollAngleStart, ImageWidth, ImageHeight, MapWidth, MapHeight)
  77. *
  78. * 3. Unroll the surface (online)
  79. *
  80. * Resize the window according to the size
  81. * of the unrolled image.
  82. dev_resize_window_fit_size (0, 0, MapWidth, MapHeight, -1, -1)
  83. * If it can be ensured that the vial always appears
  84. * at the same position, the map can be used in runtime images
  85. * to efficiently unwrap the surface of the vial.
  86. map_image (Image, Map, ImageMapped)
  87. dev_display (ImageMapped)
  88. dev_disp_text ('Unrolled label', 'window', 'top', 'left', 'black', [], [])
复制代码

代码位置:
  1. %HALCONEXAMPLES%\hdevelop\Calibration\Multi-View\calibrate_cameras_hypercentric.hdev
复制代码
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
暗翼小哥 发表于 2024-8-24 08:44:55 | 显示全部楼层
感谢大佬的分享,我来学习一下
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
wenbo_bob 发表于 2024-8-24 09:38:59 | 显示全部楼层
学习一下
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
鑫旺兴 发表于 2024-8-24 21:05:09 | 显示全部楼层
谢谢分享!
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
fishz 发表于 4 天前 | 显示全部楼层
感谢分享
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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