没有项目描述
mesh-renderer的Python项目详细描述
tf网格渲染器
这是一个可微的三维网格渲染器,使用tensorflow。 Original repository。
这个for将它发送到pypi,并删除bazel作为安装依赖项
(例如,使用python3 setup.py install
)。
安装
pip install mesh_renderer
使用量
# load your geometry (this is a cube):
object_vertices = np.array([[-1, -1, 1], [-1, -1, -1], [-1, 1, -1], [-1, 1, 1], [1, -1, 1],
[1, -1, -1], [1, 1, -1], [1, 1, 1]])
object_triangles = np.array([[0, 1, 2], [2, 3, 0], [3, 2, 6], [6, 7, 3], [7, 6, 5], [5, 4, 7],
[4, 5, 1], [1, 0, 4], [5, 6, 2], [2, 1, 5], [7, 4, 0], [0, 3, 7]], dtype=np.int32)
object_vertices = tf.constant(object_vertices, dtype=tf.float32)
object_triangles = tf.constant(object_triangles, dtype=tf.int32)
object_normals = tf.nn.l2_normalize(object_vertices, dim=1)
# rotate the geometry:
angles = [[-1.16, 0.00, 3.48]]
model_rotation = camera_utils.euler_matrices(angles)[0, :3, :3]
# camera position:
eye = tf.constant([[0.0, 0.0, 6.0]], dtype=tf.float32)
lightbulb = tf.constant([[0.0, 0.0, 6.0]], dtype=tf.float32)
center = tf.constant([[0.0, 0.0, 0.0]], dtype=tf.float32)
world_up = tf.constant([[0.0, 1.0, 0.0]], dtype=tf.float32)
vertex_diffuse_colors = tf.reshape(tf.ones_like(vertices), [1, vertices.get_shape()[0].value, 3])
light_positions = tf.expand_dims(lightbulb, axis=0)
light_intensities = tf.ones([1, 1, 3], dtype=tf.float32)
ambient_color = tf.constant([[0.0, 0.0, 0.0]])
vertex_positions = tf.reshape(
tf.matmul(vertices, model_rotation, transpose_b=True),
[1, vertices.get_shape()[0].value, 3])
desired_normals = tf.reshape(
tf.matmul(normals, model_rotation, transpose_b=True),
[1, vertices.get_shape()[0].value, 3])
# render is a tf.Tensor 3d tensor of shape height x width x 4 (r, g, b, a)
# you can backpropagate through it.
render = mesh_renderer.mesh_renderer(
vertex_positions, triangles, desired_normals,
vertex_diffuse_colors, eye, center, world_up, light_positions,
light_intensities, image_width, image_height,
ambient_color=ambient_color,
)
原始自述文件
这是一个可微的三维网格渲染器,使用tensorflow。
这不是谷歌的官方产品。
渲染器的接口由mesh_renderer.py和 光栅化三角形.py,它提供可以添加到 张量流图。渲染器的内部是由C++内核处理的。
对C++渲染内核的输入是一个三维顶点列表和一个 三角形,其中三角形由三个顶点ID的列表组成。这个 渲染器的输出是一对包含三角形id和 重心重量。重心权重图像中的像素值是 像素中心点相对于该像素处三角形的权重 (由三角形id标识)。渲染器提供 像素中心相对于顶点的重心权重 位置。
任何近似误差源于A的三角形ID的假设。 像素不会随着顶点的移动而改变。这是合理的 顶点位置小变化的逼近。即使三角形id 如果发生变化,导数将通过外推重心计算 一个相邻三角形的权重,这将产生一个很好的近似 网格很光滑。误差主要来源于遮挡边界,以及 尤其是在开放网格的边缘,背景出现在相反的位置 三角形的边缘。
实现的算法由olano和greer“三角扫描”描述。 使用二维齐次坐标的转换,“HWWS 1997。
如何构建
按照install TensorFlow using virtualenv的说明操作。
从(tensorflow)virtualenv:
(tensorflow)$ ./runtests.sh
脚本使用python解释器调用bazel规则
$VIRTUAL_ENV/bin/python
。如果你不使用virtualenv,bazel test ...
可能
足够了。
引文
如果您在研究中使用此渲染器,请引用this paper:
三维可变形模型回归的无监督训练。凯尔·热那瓦、福雷斯特·科尔、亚伦·马斯基诺、亚伦·萨纳、丹尼尔·弗拉西奇和威廉·弗里曼。CVPR 2018,第8377-8386页。
@InProceedings{Genova_2018_CVPR,
author = {Genova, Kyle and Cole, Forrester and Maschinot, Aaron and Sarna, Aaron and Vlasic, Daniel and Freeman, William T.},
title = {Unsupervised Training for 3D Morphable Model Regression},
booktitle = {The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
month = {June},
year = {2018}
}
萨福半身像:https://cdn.thingiverse.com/zipfiles/ac/39/53/07/80/Bust_of_Sappho_.zip