没有项目描述

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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java使用唯一的按钮标签单击按钮   代码生成如何使用Java codeModel为数组的特定索引赋值   java如何批量执行Camel SQL插入   java iText 7将ltv添加到现有签名   内存管理Java应用程序突然停止几天后(810)   带MySQL的java注册表单JavaFX在intellij中失败   如何使用eclipse为windows azure java项目启用远程调试   一种通用的java输入输出设计模式   java Android XML(RSS)忽略引号(“”)   java帮助:安卓中的8 X 10 2维按钮数组   java启动Android项目   JWrapper构建java应用程序   java如何在Android应用程序中设置基于日期/时间的默认页面加载?   java循环程序在完成后返回到起点   java Hibernate:更好的整体类还是多类映射?   回溯数独解算器的递归问题[Java]   java查找类用法   java如何在SpringWebFlow中将多个模型绑定到一个视图?