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

它的代码如下

bash 复制代码
dev_close_window ()
dev_update_on ()
ImagePath := 'stereo/board/'
Image1 := ImagePath + '/board_l_01'
Image2 := ImagePath + '/board_r_01'
* 
* Define the camera parameters
gen_cam_par_area_scan_division (0.0131205, -665.85466, 1.4803422e-005, 1.48e-005, 155.90117, 126.703971, 320, 240, CamParamL)
gen_cam_par_area_scan_division (0.0131712, -728.9579, 1.4799849e-005, 1.48e-005, 163.265701, 119.310684, 320, 240, CamParamR)
create_pose (0.15350044, -0.003732778, 0.04481715, 0.1736607, 319.8612, 359.8945, 'Rp+T', 'gba', 'point', RelPose)
* 
* Generate a disparity image
* ******************************************
* 
* Generate the rectification maps
gen_binocular_rectification_map (MapL, MapR, CamParamL, CamParamR, RelPose, 1, 'viewing_direction', 'bilinear', RectCamParL, RectCamParR, CamPoseRectL, CamPoseRectR, RectLPosRectR)
* 
* Read and rectify the stereo image pair
read_image (ImageL, Image1)
read_image (ImageR, Image2)
map_image (ImageL, MapL, ImageRectifiedL)
map_image (ImageR, MapR, ImageRectifiedR)
* 
* Display the left rectified image
get_image_size (ImageRectifiedL, WidthL, HeightL)
dev_open_window (0, 0, WidthL, HeightL, 'white', WindowHandle1)
set_display_font (WindowHandle1, 11, 'mono', 'true', 'false')
dev_display (ImageRectifiedL)
disp_message (WindowHandle1, 'Left rectified image', 'window', 10, 10, 'black', 'true')
* 
* Display the right rectified image
dev_open_window (0, WidthL + 10, WidthL, HeightL, 'white', WindowHandle2)
set_display_font (WindowHandle2, 11, 'mono', 'true', 'false')
dev_display (ImageRectifiedL)
disp_message (WindowHandle2, 'Right rectified image', 'window', 10, 10, 'black', 'true')
disp_continue_message (WindowHandle2, 'black', 'true')
stop ()
* 
* Determine the disparity image.
binocular_disparity (ImageRectifiedL, ImageRectifiedR, DisparityImage, Score, 'ncc', 17, 17, 5, 10, 40, 1, 0.1, 'left_right_check', 'none')
* 
* Fill the gaps in the disparity image
*填补视差图中的空白
get_domain (DisparityImage, RegionInpainting)
****求没有视差值得区域的补集
complement (RegionInpainting, RegionInpainting)
*****扩展DisparityImage到它最小的外接矩形的全域
full_domain (DisparityImage, DisparityImage)
get_domain (DisparityImage, Domain)
*****对全域disparityimage的补集区域,进行谐波差值结算
harmonic_interpolation (DisparityImage, RegionInpainting, DisparityImage, 0.001)
*****补完以后可以看到,没有差值的部分,出现了差值,具体的插补过程不太懂,死记住先用吧

* Display the disparity image
dev_set_window (WindowHandle1)
dev_display (DisparityImage)
disp_message (WindowHandle1, 'Disparity image', 'window', 10, 10, 'black', 'true')
* 
* Compute the 3D coordinates
* *******************************************
* 
* Transform the disparity image into images X, Y and Z.
* The gray values in X, Y and Z represent the x, y, and z
* coordinates of the pixels (Row, Column).
*****一直在找的一个参数,将disparityimage值匹配回左相机的图像中去
disparity_image_to_xyz (DisparityImage, X, Y, Z, RectCamParL, RectCamParR, RectLPosRectR)
* 
* Visualize the 3D points in the 3D space
* *******************************************
* 
* Scale Z (for better visualization)
scale_image (Z, Z, 2, 0)
* 
* Reduce impact of inaccuracies in visualization
threshold (Z, Regions, 0.415, 0.5)
reduce_domain (Z, Regions, ZThresholded)
* Add the gray values to the point cloud.
xyz_attrib_to_object_model_3d (X, Y, ZThresholded, ImageRectifiedL, '&gray', ObjectModel3D)
* 
* Visualize the result
prepare_object_model_3d (ObjectModel3D, 'segmentation', 'true', 'max_area_holes', 100)
create_pose (-0.025, -0.37, 1.7, 300, 12, 180, 'Rp+T', 'gba', 'point', Pose)
visualize_object_model_3d (WindowHandle2, ObjectModel3D, [], Pose, 'color_attrib', '&gray', [], [], [], PoseOut)
相关推荐
Black蜡笔小新6 小时前
自动化AI算法训练服务器DLTM助力医学影像分析进入AI智能分析新时代
人工智能·算法·自动化
手写码匠7 小时前
深入解析大模型架构之争:全能通用模型 vs 领域专精模型
人工智能·深度学习·算法·aigc
浅念-8 小时前
LeetCode 回溯算法题——综合练习
数据结构·c++·算法·leetcode·职场和发展·深度优先·dfs
列星随旋8 小时前
线段树和树状数组的学习
学习·算法
全糖可乐气泡水10 小时前
Codex适配国产信创环境安装部署与技术适配全解析
开发语言·git·python·算法·百度
h_a_o777oah10 小时前
状态机+划分型 DP :深度解析K-划分问题下 DP 状态的转移逻辑(洛谷P2679 P2331 附C++代码)
c++·算法·动态规划·acm·状态机dp·划分型dp·滚动数组优化
05候补工程师10 小时前
从算法理想向工程现实的跨越:SLAM 核心架构、思维误区与 Nav2 实战避坑指南
人工智能·算法·安全·架构·机器人
threelab11 小时前
Three.js 加载 3D Tiles 瓦片数据 | 三维可视化 / AI 提示词
开发语言·前端·javascript·人工智能·3d·着色器
手写码匠12 小时前
Android 17 适配实战指南:新特性解读、隐私变更与迁移全攻略
人工智能·深度学习·算法·aigc