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)
相关推荐
Binky67812 分钟前
力扣--贪心篇(1)
数据结构·算法·leetcode
sinat_2554878113 分钟前
文件I/O流
java·jvm·算法
北辰水墨14 分钟前
【算法篇】单调栈的学习
c++·笔记·学习·算法·单调栈
源代码•宸16 分钟前
goframe框架签到系统项目开发(分布式 ID 生成器、雪花算法、抽离业务逻辑到service层)
经验分享·分布式·mysql·算法·golang·雪花算法·goframe
AIpanda88817 分钟前
当智能化工具应用于企业,如何借助AI销冠系统提升工作效率?
算法
进击的小头22 分钟前
01_嵌入式C与控制理论入门:从原理到MCU实战落地
c语言·单片机·算法
what_201825 分钟前
list 对象里面 嵌套list对象,对象的属性 有浮点数,list<浮点数> 对list对象求均值
算法·均值算法
wanghowie31 分钟前
01.09 Java基础篇|算法与数据结构实战
java·数据结构·算法
郝学胜-神的一滴39 分钟前
GLSL语法详解:从入门到实战
c++·算法·图形渲染
qq_4634084241 分钟前
React Native跨平台技术在开源鸿蒙中使用内置的`fetch` API或者第三方库如`axHarmony`来处理网络通信HTTP请求
javascript·算法·react native·react.js·http·开源·harmonyos