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)
相关推荐
阿巴~阿巴~26 分钟前
IPv4地址转换函数详解及C++容器安全删除操作指南
linux·服务器·c++·网络协议·算法·c++容器安全删除操作·ipv4地址转换函数
TT哇27 分钟前
【面经 每日一题】面试题16.25.LRU缓存(medium)
java·算法·缓存·面试
SKYDROID云卓小助手1 小时前
无人设备遥控器之差分信号抗干扰技术
网络·stm32·单片机·嵌入式硬件·算法
美狐美颜SDK开放平台1 小时前
什么是美颜sdk?美型功能开发与用户体验优化实战
人工智能·算法·ux·直播美颜sdk·第三方美颜sdk·视频美颜sdk
小一亿1 小时前
【3ds Max动画】烟花:超级喷射粒子,荧光粒子效果
学习·3d·图形渲染·3dsmax·动画
@宁兰2 小时前
算法实现总结 - C/C++
c语言·c++·算法
zstar-_2 小时前
3D高斯泼溅的后处理方式
3d
Doro再努力2 小时前
2025_11_14洛谷【入门1】数据结构刷题小结
前端·数据结构·算法
蒙奇D索大2 小时前
【算法】回溯算法精讲:从深度优先搜索到剪枝优化
经验分享·笔记·算法·深度优先·剪枝·改行学it
QTreeY1232 小时前
yolov5/8/9/10/11/12/13+deep-oc-sort算法的目标跟踪实现
人工智能·算法·yolo·目标检测·计算机视觉·目标跟踪