Comments (10)
Here's an efficient way to do it all in the same renderer!
# Assume we have an offscreen renderer and a scene
segimg = np.zeros((height, width), dtype=np.uint8)
flags = RenderFlags.DEPTH_ONLY
# Render full depth
full_depth = renderer.render(scene, flags=flags)
# Hide all mesh nodes
for mn in scene.mesh_nodes:
mn.mesh.is_visible = False
# Now, iterate through them, enabling each one
for i, node in enumerate(scene.mesh_nodes):
node.mesh.is_visible = True
depth = renderer.render(scene, flags=flags)
mask = np.logical_and(
(np.abs(depth - full_depth) < 1e-6), np.abs(full_depth) > 0
)
segimg[mask] = i + 1
node.mesh.is_visible = False
# Show all meshes again
for mn in scene.mesh_nodes:
mn.mesh.is_visible = True
This bit of code will produce a segimg containing what you want. Does that work for you, or do you still want flat shading?
from pyrender.
HI @mmatl! Thanks a lot for this cool library :)
Did you have time already to look into this issue again?
from pyrender.
Just found out that the instance segmentation is supported since version 0.1.41.
You can also find an example in the example.py
TL;DR:
from pyrender import RenderFlags
nm = {node: 20*(i + 1) for i, node in enumerate(scene.mesh_nodes)} # Node->Seg Id map
seg = r.render(scene, RenderFlags.SEG, nm)[0]
from pyrender.
Sorry y'all! Got sidetracked at work. Will try to push this out soon. It should be pretty easy to write a shader to do exactly this in a single forward pass.
from pyrender.
Hi! The standard way to render instance masks actually is to render individual depth images and do a depth difference between each depth image and the overall image, as you've been doing so far. In principle, it's possible to render instance masks in a single pass if you do totally flat shading and give each mesh a unique color, but for now, pyrender doesn't support totally flat shading. I can add it in as an option if you think it'd be useful, though. I haven't been having performance issues with the depth differencing method myself :)
from pyrender.
@mmatl Thanks a lot! This is helpful but may not be enough.
I'm trying to render instance masks for video sequences from a big 3D dataset containing 1500 scenes. This roughly amounts to a total of 2.5 million images.
If I have to render each frame 20-30
times (once for each object/mesh), it seems (based on a few experimental runs) the whole thing might take up to a month. With flat-shading, however, it would be 1-2 days which is more reasonable.
It would be good to have a flat shading option. I'd be happy to help you with the implementation with some guidance!
from pyrender.
@shubham-goel Hmm after thinking about this for a bit, I think that there may be a better way to do this. It's probably better to write a custom vertex + fragment shader and just give you the option to use those in the rendering flags. Let me try to mock that up real fast.
Going to be out and about during the day today, but I should be able to get something to you tonight or tomorrow.
from pyrender.
Also, do run multiple processes at once! Your GPU/CPU should be able to handle it, and this sort of task is definitely easily parallelizable.
from pyrender.
@shubham-goel Hmm after thinking about this for a bit, I think that there may be a better way to do this. It's probably better to write a custom vertex + fragment shader and just give you the option to use those in the rendering flags. Let me try to mock that up real fast.
Going to be out and about during the day today, but I should be able to get something to you tonight or tomorrow.
Thanks for the awesome library. Did you add this feature? If so, could you please share an example for that?
from pyrender.
Just found out that the instance segmentation is supported since version 0.1.41.
You can also find an example in the example.py
TL;DR:
from pyrender import RenderFlags nm = {node: 20*(i + 1) for i, node in enumerate(scene.mesh_nodes)} # Node->Seg Id map seg = r.render(scene, RenderFlags.SEG, nm)[0]
This did the job for me, thanks for sharing!
from pyrender.
Related Issues (20)
- Request for Assistance: Obtaining Pixel-to-Face Index in Pyrender
- BROKEN LINK: Google colab notebooks HOT 1
- Invalid device ID (0), Pyrender NOT working on Python 3.10 HOT 5
- Inverted triangles?
- How to retrieve intrinsic camera parameters from PerspectiveCamera
- Textures rendering slanted
- Sphere Rendered with Non-reflective Material Not Appearing Black
- offscreen error
- 'Viewer' object has no attribute 'render'. Did you mean: '_render'?
- Interpolation artifacts in segmentation masks.
- Unable to get color on running the bottle example code HOT 1
- Wrong depth rendering in WSL-ubuntu environment
- Path3D type error when loading trimesh scene
- GLB is not rendered correctly HOT 1
- How to properly merge the Scenes from multiple trimeshes?
- Request for Release of Tag 0.1.46 with auto_start Option
- Cannot render SpecularGlossinessMaterial HOT 1
- jupyter notebook support?
- Attempt to call an undefined function glGenVertexArrays, check for bool(glGenVertexArrays) before calling HOT 3
- OpenGL.error.NullFunctionError: Attempt to call an undefined function glGenVertexArrays, check for bool(glGenVertexArrays) before calling
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyrender.