A toolbox of eccentric functions for visualizing and processing images and meshes. Tested with python version 3.6.9.
To install:
pip install git+https://github.com/nikwl/lookit.git
To render offscreen using the GPU, set the PYOPENGL_PLATFORM to egl.
import os
# Use for GPU rendering
os.environ["PYOPENGL_PLATFORM"] = "egl"
If you need to render offscreen using the cpu, install a newer version of PyOpenGL
pip install PyOpenGL==3.1.5
The use the osmesa rendering engine
import os
# Use for CPU rendering
os.environ["PYOPENGL_PLATFORM"] = "osmesa"
Create a summary render of all meshes in a given directory.
python -m lookit.meshview <root_directory> <image_file.jpg> --ext .ply
Load a mesh, render, and view a mesh.
from PIL import Image
import trimesh
import lookit
# Load a mesh
mesh = trimesh.load("examples/mesh.ply")
# Render the mesh with lookit
render = lookit.mesh.render(
mesh=mesh,
resolution=(1920, 1080),
mode="RGB",
)
# Show it in an interactive viewer
Image.fromarray(render).show()
Set a camera pose manually and then use this pose to generate an offscreen render. This is really helpful if you need to figure out a good camera pose to render a bunch of models from. The function trimesh_set_camera
will also give you feedback on if your model is too large/too small for the renderer, which gets around some common visualization issues people often run into.
import os
os.environ["PYOPENGL_PLATFORM"] = "egl" # For offscreen rendering
from PIL import Image
import trimesh
import lookit
# Load a model
m = trimesh.load("examples/mesh.ply")
# Get a camera pose
camera_pose = lookit.mesh.trimesh_set_camera(m)
# Render from that camera pose
render = lookit.mesh.render(
m,
bg_color=255,
camera_pose=camera_pose,
)
Image.fromarray(render).show()
Create a point cloud from a given camera perspective, then render and view it.
from PIL import Image
import trimesh
import lookit
ptcld = lookit.mesh.render(
mesh=trimesh.load("examples/mesh.ply"),
resolution=(1920, 1080),
modality="pointcloud",
)
Image.fromarray(
lookit.mesh.render(
mesh=lookit.mesh.trimesh_normalize(
trimesh.PointCloud(ptcld)
),
resolution=(1920, 1080),
yrot=0,
xrot=180,
)
).show()
Create and save a rotating gif of a mesh.
from PIL import Image
import trimesh
import lookit
gif = lookit.mesh.create_gif_rot(
trimesh.load("examples/mesh.ply")
)
ptcld = lookit.mesh.render(
mesh=trimesh.load("examples/mesh.ply"),
resolution=(1920, 1080),
modality="pointcloud",
)
Image.fromarray(
lookit.mesh.render(
mesh=lookit.mesh.trimesh_normalize(
trimesh.PointCloud(ptcld)
),
resolution=(1920, 1080),
yrot=0,
xrot=180,
)
).show()
You should get something that looks like this:
Plot a command line histogram of an image.
from PIL import Image
import lookit
lookit.image.summary(Image.open("img.jpg"))