Depth map generator written from scratch in C++ and Python. CPU-only, self-contained, no external dependencies. Ideal for off-screen online depth data generation from meshes in Python scripts.
Multi-layer depth map implementation comping soon (see 3D Scene Reconstruction with Multi-layer Depth and Epipolar Transformers, ICCV 2019).
Only tested on Python 3.6-3.8 on Ubuntu 18.04.
# Make sure pip is up to date: pip install -U pip
pip install mesh-to-depth
For other python versions and distributions, you may have to compile from source. See this page for supported precompiled binaries.
import numpy as np
import mesh_to_depth as m2d
params = []
params.append({
'cam_pos': [1, 1, 1], 'cam_lookat': [0, 0, 0], 'cam_up': [0, 1, 0],
'x_fov': 0.349, # End-to-end field of view in radians
'near': 0.1, 'far': 10,
'height': 240, 'width': 320,
'is_depth': True, # If false, output a ray displacement map, i.e. from the mesh surface to the camera center.
})
# Append more camera parameters if you want batch processing.
# Load triangle mesh data. See python/resources/airplane/models/model_normalized.obj
vertices = ... # An array of shape (num_vertices, 3) and type np.float32.
faces = ... # An array of shape (num_faces, 3) and type np.uint32.
depth_maps = m2d.mesh2depth(vertices, faces, params, empty_pixel_value=np.nan)
Visualize:
import matplotlib.pyplot as pt
pt.imshow(depth_maps[0], interpolation='none')
pt.colorbar()
See also: python/tests
Requires pytest
.
git clone --recurse-submodules https://github.com/daeyun/mesh_to_depth
cd mesh_to_depth
Then either build the .so
files with bash ./cpp/scripts/build_all.sh
or do pip install -e .
. Then run rests:
cd python
pytest ./tests
pip install tox
git clone --recurse-submodules https://github.com/daeyun/mesh_to_depth
cd mesh_to_depth
tox