Skip to content

nikwl/lookit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lookit

A toolbox of eccentric functions for visualizing and processing images and meshes. Tested with python version 3.6.9.

Installation

To install:

pip install git+https://github.com/nikwl/lookit.git

Rendering offscreen

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"

Functions and Examples

Command Line Render

Create a summary render of all meshes in a given directory.

python -m lookit.meshview <root_directory> <image_file.jpg> --ext .ply

Lookit Basic Usage

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 Camera Pose

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 PointCloud From a Mesh

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 a Rotating GIF

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: rotating mesh

Image Histogram

Plot a command line histogram of an image.

from PIL import Image
import lookit
lookit.image.summary(Image.open("img.jpg"))

About

A tool for, well, looking at stuff.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages