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

如何使用Open3D在点云的指定坐标位置显示图片?

在Open3D点云场景指定位置显示图片的实现方法

Open3D没有直接提供在3D空间指定位置显示图片的API,但可以通过将图片转为带纹理的平面网格的方式实现,步骤如下:

1. 核心思路

把图片作为纹理映射到一个平面网格上,再将这个网格放置到点云场景的指定坐标位置,最后和点云一起渲染。

2. 具体实现代码

import open3d as o3d
import numpy as np

def create_textured_plane(image_path, plane_size=(1.0, 1.0), center=(0, 0, 0)):
    # 加载图片作为纹理
    img = o3d.io.read_image(image_path)
    
    # 创建平面网格的顶点(四边形由两个三角形组成)
    width, height = plane_size
    vertices = [
        [-width/2, -height/2, 0],
        [width/2, -height/2, 0],
        [width/2, height/2, 0],
        [-width/2, height/2, 0]
    ]
    vertices = np.array(vertices)
    # 平移到指定中心坐标
    vertices += np.array(center)
    
    # 定义三角形面索引
    triangles = [[0, 1, 2], [0, 2, 3]]
    
    # 创建网格并设置纹理
    mesh = o3d.geometry.TriangleMesh()
    mesh.vertices = o3d.utility.Vector3dVector(vertices)
    mesh.triangles = o3d.utility.Vector3iVector(triangles)
    # 设置纹理坐标(对应图片的四个角落)
    mesh.triangle_uvs = o3d.utility.Vector2dVector([
        [0, 0], [1, 0], [1, 1],
        [0, 0], [1, 1], [0, 1]
    ])
    mesh.textures = [img]
    
    # 计算法向量确保纹理正确显示
    mesh.compute_vertex_normals()
    return mesh

# 加载点云
pcd = o3d.io.read_point_cloud("your_point_cloud.pcd")

# 创建带图片的平面网格,指定位置(1, 0, 0),平面大小可按需调整
image_plane = create_textured_plane("your_image.jpg", plane_size=(2.0, 2.0), center=(1, 0, 0))

# 可视化点云和平面
vis = o3d.visualization.Visualizer()
vis.create_window()
vis.add_geometry(pcd)
vis.add_geometry(image_plane)
vis.run()
vis.destroy_window()

3. 关键细节调整

  • 平面朝向:如果需要平面朝向相机,可通过mesh.rotate()调整旋转角度,比如绕x轴旋转90度:mesh.rotate(mesh.get_rotation_matrix_from_xyz((np.pi/2, 0, 0)))
  • 图片比例适配:获取图片宽高比,设置plane_size时保持相同比例避免拉伸,比如图片宽640高480,可设plane_size=(4.0, 3.0)
  • 透明度设置:若要半透明效果,可给网格设置带alpha通道的颜色,比如mesh.paint_uniform_color([1,1,1,0.5]),同时开启背面渲染:vis.get_render_option().mesh_show_back_face = True

内容的提问来源于stack exchange,提问作者Dang Manh Truong

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 04:40:54