Giter Site home page Giter Site logo

lookit's Introduction

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"))

lookit's People

Contributors

nikwl avatar

Stargazers

Anthony Lombardi avatar Xinchao Song avatar  avatar Mingjun Li avatar

Watchers

Xinchao Song avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.