3D几何轻松实现。
项目描述
visu3d - 3D几何轻松实现
visu3d
是Torch/TF/Jax/Numpy与你的程序之间的抽象层。它提供
- 标准3D几何原语(
Ray
,Camera
,Transform
,...)。你可以将那些标准原语与你的自定义原语结合起来。 - 所有内容都可以轻松可视,无需任何样板代码。检查并调试相机姿态、轨迹...
- 所有原语都是
dataclass_array
,可重新排列、切片...,就像它们是NumPy数组一样。 - 所有内容都是可扩展的,你可以逐步选择所需的功能,并用你的自定义原语替换任何标准原语。
核心功能
所有内容都是v3d.DataclassArray
: dataclass表现得像np.array
(具有索引、切片、形状操作、向量化...)。
# Single ray
ray = v3d.Ray(pos=[0, 0, 0], dir=[1, 1, 1])
assert rays.shape == ()
# Multiple rays batched together
rays = v3d.Ray(pos=np.zeros((B, H, W, 3)), dir=np.ones((B, H, W, 3)))
assert rays.shape == (B, H, W)
rays = rays.reshape('b h w -> b (h w)') # Native `einops` support
top_left_ray = rays[..., 0, 0] # (b, h, w) -> (b,)
rays = rays.flatten()
rays = rays[rays.norm() > 0] # Filter invalid rays
所有内容都可以交互式可视化
每个对象都有一个.fig
属性用于交互式可视化
rays.fig # Plot the rays
同时显示多个对象
v3d.make_fig([cam, rays, point_cloud])
使用Colab魔法自动绘图
v3d.auto_plot_figs() # Once at the start of the Colab
cam, rays, point_cloud # Tuple auto-displayed without `v3d.make_fig` call
相同的代码在Torch、Jax、TensorFlow、Numpy上无缝工作。
rays = rays.as_jax() # .as_tf(), as_np(), .as_jax()
assert isinstance(rays.pos, jnp.ndarray)
assert rays.xnp is jnp
rays = rays.as_torch()
assert isinstance(rays.pos, torch.Tensor)
assert rays.xnp is torch
具有对自动微分、jax.vmap
、jax.tree_utils
...的原生支持。
原语
常用原语(Ray
、Camera
、Transform
等),用户可以用它们来表达意图,而不是数学表达式。
H, W = (256, 1024)
cam_spec = v3d.PinholeCamera.from_focal(
resolution=(H, W),
focal_in_px=35.,
)
cam = v3d.Camera.from_look_at(
spec=cam_spec,
pos=[5, 5, 5],
target=[0, 0, 0], # Camera looks at the scene center
)
rays = cam.rays() # Rays in world coordinates
# Project `(*shape, 3)` world coordinates into `(*shape, 2)` pixel coordinates.
px_coords = cam.px_from_world @ point_cloud
查看API获取原语的全列表。
创建自己的原语非常简单。
将任何数据类转换为数据类数组非常简单
- 继承自
v3d.DataclassArray
- 使用
etils.array_types
来注解数组字段(或显式使用my_field: Any = dca.field(shape=, dtype=)
而不是dataclasses.field
)
from etils.array_types import FloatArray
class MyRay(v3d.DataclassArray):
pos: FloatArray[..., 3]
dir: FloatArray[..., 3]
rays = MyRay(pos=jnp.zeros((H, W, 3)), dir=jnp.ones((H, W, 3)))
assert rays.shape == (H, W)
v3d
通过实现相应的协议,使您能够轻松选择所需的特性。
文档
开始使用Colab教程(在文档中)是最佳方式。
安装
pip install visu3d
用法
import visu3d as v3d
安装
pip install visu3d
这不是一个官方的Google产品。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源分布
visu3d-1.5.3.tar.gz (34.5 kB 查看哈希值)
构建分布
visu3d-1.5.3-py3-none-any.whl (49.4 kB 查看哈希值)