Python示例,用于使用内置摄影机从点云创建深度贴图

2024-05-16 09:30:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我在C++中见过大量的OpenCV代码,关于如何将3D点云转换成深度图,有摄像机内含物(矩阵和宽度、高度、FX、FY、CX和CY),但是我没有看到任何关于用Python将点云转换成深度图的代码。我曾尝试使用open3d,它在从深度图像转换为点云时效果很好,但在从点云转换为深度贴图时,我会得到一个热图,它会随机缩放,因此当我在open3d中从深度贴图重新导入点云时,深度贴图是不正确的(因为我必须从热图转换为深度贴图),深度贴图与rgb图像不一致。 这是我在open3d中的代码,用于将rgb和深度贴图转换为open3d中的点云

intrinsics = o3d.camera.PinholeCameraIntrinsic(640, 480 ,525.0, 525.0, 319.5, 239.5) 
'''
width (int) – Width of the image.

height (int) – Height of the image.

fx (float) – X-axis focal length

fy (float) – Y-axis focal length.

cx (float) – X-axis principle point.

cy (float) – Y-axis principle point.
'''
depth_raw = o3d.io.read_image("./00000.png")
color_raw = o3d.io.read_image("./color.jpg")
rgbd_image = create_rgbd_image_from_color_and_depth(
    color_raw, depth_raw)

pcd =  o3d.geometry.create_point_cloud_from_rgbd_image(rgbd_image, o3d.camera.PinholeCameraIntrinsic(intrinsics))
pcd.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]]) # flips to it is right side up
o3d.visualization.draw_geometries([pcd])
np.savetxt("./pcd.txt", np.asarray(pcd.points))

有人能帮我用python、opencv或任何其他库将点云投影到深度图的代码吗


Tags: 代码图像imagerawrgbfloatcolorpoint