You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Open3D从深度图像创建张量点云报错求助

问题解决步骤

1. 修正参数名称:depth_trunc → depth_max

Open3D张量版本(o3d.t.geometry)的create_from_depth_image函数,参数名是**depth_max**,而非CPU版本的depth_trunc,这是参数不匹配的核心原因之一。

2. 统一张量数据类型为Float32

报错显示你的内参张量是Float64类型,但函数期望的是Float32(参考默认外参的类型),需要将内参转换为Float32类型。

3. 可选:提前将数据移至GPU(若需GPU处理)

如果最终要在GPU上处理点云,可以在创建张量时直接指定CUDA设备,避免后续迁移可能出现的问题。

修正后的代码

import numpy as np
import open3d as o3d

# 假设frame.depth_data是1920x1080的UInt16深度数据
depth_np = np.asarray(frame.depth_data)
# 直接创建CUDA张量(需GPU处理时),否则可去掉device参数保留CPU
depth_data = o3d.core.Tensor(depth_np, dtype=o3d.core.Dtype.UInt16, device=o3d.core.Device("CUDA:0"))
img_depth = o3d.t.geometry.Image(depth_data)

depth_multiplier = 6
# 将内参转换为Float32,可选指定CUDA设备
intrinsic_mat = o3d.core.Tensor(
    np.array([[1366.19, 0.0, 971.087], [0.0, 1364.69, 545.059], [0.0, 0.0, 1.0]]),
    dtype=o3d.core.Dtype.Float32,
    device=o3d.core.Device("CUDA:0")  # 无需GPU时可删除该行
)

# 使用depth_max替代depth_trunc,同时指定Realsense默认的depth_scale
point_cloud = o3d.t.geometry.PointCloud.create_from_depth_image(
    img_depth,
    intrinsic_mat,
    depth_max=0.75 * depth_multiplier,
    depth_scale=1000.0  # Realsense D435深度数据单位为毫米,转为米需除以1000
)

# 若创建时未指定CUDA设备,再执行迁移
# point_cloud.cuda()

额外说明

  • Realsense D435的深度数据默认是16位无符号整数,单位为毫米,depth_scale=1000.0是将深度值转换为米的正确设置。
  • 确保使用的Open3D版本为0.15及以上,旧版本的张量API可能存在差异。

内容的提问来源于stack exchange,提问作者Martin Pedersen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 07:55:29