0


halcon3d disparity_image_to_xyz非常重要的算子及使用条件

双目立体视觉中最重要的一步

通过双目立体视觉行成disparityimage以后,如何或得点云。这个问题困扰了我很久,在形成视差图后,怎么把或得的结果,返回到左相机视图中,然后形成点云,这里最重要的就是这个算子disparity_image_to_xyz

Disparity : 视差图,可以通过binocular_disparity或得
X, Y, Z : 对应的x,y,z坐标,通过xyz_to_object_model_3d形成3d模型
CamParamRect1,左相机的内参(主相机)
CamParamRect2, 右相机的内参(辅相机)
RelPoseRect : 右相机相对于左相机的旋转矩阵,可以通过binocular_calibration或得,也就是双目相机的标定

这里有最重要的一步,就是disparityimage的区域填充

为什么要填充,在disparityimage形成的过程中,有些区域是没有值得,填充就是通过一定的运算,给这些空的区域进行赋值。halcon里面是这么做得,最后一步,有懂得朋友,欢迎交流学习!

*填补视差图中的空白,先获取有差值的区域
get_domain (DisparityImage, RegionInpainting)
****求没有视差值得区域的补集,这个区域如果system的设置clip_region为false时会比较大
complement (RegionInpainting, RegionInpainting)
*****扩展DisparityImage到它最小的外接矩形的全域
full_domain (DisparityImage, DisparityImage)
get_domain (DisparityImage, Domain)
*****对全域disparityimage的补集区域,进行谐波差值结算

harmonic_interpolation (DisparityImage, RegionInpainting, DisparityImage, 0.001)
*****补完以后可以看到,没有差值的部分,出现了差值,具体的插补过程不太懂,死记住先用吧

具体大家可以参考实例 disparity_image_to_xyz
它的代码如下

  1. dev_close_window ()
  2. dev_update_on ()
  3. ImagePath :='stereo/board/'
  4. Image1 := ImagePath + '/board_l_01'
  5. Image2 := ImagePath + '/board_r_01'
  6. *
  7. * Define the camera parameters
  8. gen_cam_par_area_scan_division (0.0131205, -665.85466, 1.4803422e-005, 1.48e-005, 155.90117, 126.703971, 320, 240, CamParamL)
  9. gen_cam_par_area_scan_division (0.0131712, -728.9579, 1.4799849e-005, 1.48e-005, 163.265701, 119.310684, 320, 240, CamParamR)
  10. create_pose (0.15350044, -0.003732778, 0.04481715, 0.1736607, 319.8612, 359.8945, 'Rp+T', 'gba', 'point', RelPose)
  11. *
  12. * Generate a disparity image
  13. * ******************************************
  14. *
  15. * Generate the rectification maps
  16. gen_binocular_rectification_map (MapL, MapR, CamParamL, CamParamR, RelPose, 1, 'viewing_direction', 'bilinear', RectCamParL, RectCamParR, CamPoseRectL, CamPoseRectR, RectLPosRectR)
  17. *
  18. * Read and rectify the stereo image pair
  19. read_image (ImageL, Image1)
  20. read_image (ImageR, Image2)
  21. map_image (ImageL, MapL, ImageRectifiedL)
  22. map_image (ImageR, MapR, ImageRectifiedR)
  23. *
  24. * Display the left rectified image
  25. get_image_size (ImageRectifiedL, WidthL, HeightL)
  26. dev_open_window (0, 0, WidthL, HeightL, 'white', WindowHandle1)
  27. set_display_font (WindowHandle1, 11, 'mono', 'true', 'false')
  28. dev_display (ImageRectifiedL)
  29. disp_message (WindowHandle1, 'Left rectified image', 'window', 10, 10, 'black', 'true')
  30. *
  31. * Display the right rectified image
  32. dev_open_window (0, WidthL + 10, WidthL, HeightL, 'white', WindowHandle2)
  33. set_display_font (WindowHandle2, 11, 'mono', 'true', 'false')
  34. dev_display (ImageRectifiedL)
  35. disp_message (WindowHandle2, 'Right rectified image', 'window', 10, 10, 'black', 'true')
  36. disp_continue_message (WindowHandle2, 'black', 'true')
  37. stop ()
  38. *
  39. * Determine the disparity image.
  40. binocular_disparity (ImageRectifiedL, ImageRectifiedR, DisparityImage, Score, 'ncc', 17, 17, 5, 10, 40, 1, 0.1, 'left_right_check', 'none')
  41. *
  42. * Fill the gaps in the disparity image
  43. *填补视差图中的空白
  44. get_domain (DisparityImage, RegionInpainting)
  45. ****求没有视差值得区域的补集
  46. complement (RegionInpainting, RegionInpainting)
  47. *****扩展DisparityImage到它最小的外接矩形的全域
  48. full_domain (DisparityImage, DisparityImage)
  49. get_domain (DisparityImage, Domain)
  50. *****对全域disparityimage的补集区域,进行谐波差值结算
  51. harmonic_interpolation (DisparityImage, RegionInpainting, DisparityImage, 0.001)
  52. *****补完以后可以看到,没有差值的部分,出现了差值,具体的插补过程不太懂,死记住先用吧
  53. * Display the disparity image
  54. dev_set_window (WindowHandle1)
  55. dev_display (DisparityImage)
  56. disp_message (WindowHandle1, 'Disparity image', 'window', 10, 10, 'black', 'true')
  57. *
  58. * Compute the 3D coordinates
  59. * *******************************************
  60. *
  61. * Transform the disparity image into images X, Y and Z.
  62. * The gray values in X, Y and Z represent the x, y, and z
  63. * coordinates of the pixels (Row, Column).
  64. *****一直在找的一个参数,将disparityimage值匹配回左相机的图像中去
  65. disparity_image_to_xyz (DisparityImage, X, Y, Z, RectCamParL, RectCamParR, RectLPosRectR)
  66. *
  67. * Visualize the 3D points in the 3D space
  68. * *******************************************
  69. *
  70. * Scale Z (for better visualization)
  71. scale_image (Z, Z, 2, 0)
  72. *
  73. * Reduce impact of inaccuracies in visualization
  74. threshold (Z, Regions, 0.415, 0.5)
  75. reduce_domain (Z, Regions, ZThresholded)
  76. * Add the gray values to the point cloud.
  77. xyz_attrib_to_object_model_3d (X, Y, ZThresholded, ImageRectifiedL, '&gray', ObjectModel3D)
  78. *
  79. * Visualize the result
  80. prepare_object_model_3d (ObjectModel3D, 'segmentation', 'true', 'max_area_holes', 100)
  81. create_pose (-0.025, -0.37, 1.7, 300, 12, 180, 'Rp+T', 'gba', 'point', Pose)
  82. visualize_object_model_3d (WindowHandle2, ObjectModel3D, [], Pose, 'color_attrib', '&gray', [], [], [], PoseOut)
标签: 3d 算法

本文转载自: https://blog.csdn.net/Tianwen_running/article/details/143840328
版权归原作者 Tianwen_Burning 所有, 如有侵权,请联系我们删除。

“halcon3d disparity_image_to_xyz非常重要的算子及使用条件”的评论:

还没有评论