import numpy as np
np.set_printoptions(linewidth=500, precision=1)
from menpo.rasterize import GLRasterizer
import menpo.io as mio
RENDERING A FACE
mesh = mio.import_builtin_asset('james.obj')
%matplotlib qt
viewer = mesh.view()
viewer_settings = viewer.renderer_settings
np.set_printoptions(linewidth=500, precision=1)
for k, v in viewer_settings.iteritems():
print("{}: ".format(k))
print(v)
projection_matrix: [[ 4.2e+00 0.0e+00 0.0e+00 0.0e+00] [ 0.0e+00 3.7e+00 0.0e+00 0.0e+00] [ 0.0e+00 0.0e+00 -2.2e+00 -1.9e+03] [ 0.0e+00 0.0e+00 -1.0e+00 0.0e+00]] width: 1414 model_matrix: [[ 1. 0. 0. 0.] [ 0. 1. 0. 0.] [ 0. 0. 1. 0.] [ 0. 0. 0. 1.]] view_matrix: [[ 7.7e-01 2.2e-02 -6.4e-01 -1.0e+01] [ 4.9e-02 9.9e-01 9.4e-02 3.2e+01] [ 6.4e-01 -1.0e-01 7.7e-01 -9.5e+02] [ 0.0e+00 0.0e+00 0.0e+00 1.0e+00]] height: 1600
# build a rasterizer configured from the current view
r = GLRasterizer(**viewer_settings)
# rasterize to produce an RGB image
rgb_img = r.rasterize_mesh(mesh)
%matplotlib inline
rgb_img.view()
<menpo.visualize.viewmatplotlib.MatplotlibImageViewer2d at 0x203c3278>
All rasterized images have their mask set to show what the rasterizer actually processed
rgb_img.mask.view()
<menpo.visualize.viewmatplotlib.MatplotlibImageViewer2d at 0x203ee160>
Cyrasterize gives us the ability to rasterize other information though. For instance, we can render out a XYZ floating point shape image
rgb_img, shape_img = r.rasterize_mesh_with_shape_image(mesh)
# 3rd channel is z information in model space coordinates
# note that this is NOT camera depth
shape_img.view(channels=2)
<menpo.visualize.viewmatplotlib.MatplotlibImageSubplotsViewer2d at 0x1ce2da0>