Reputation: 41
I want to generate a rendered image from the 3D model in python using pyrender
module. For this reason, I used this Code.
# Render offscreen -- make sure to set the PyOpenGL platform
import os
os.environ["PYOPENGL_PLATFORM"] = "egl"
import numpy as np
import trimesh
import pyrender
# Load the FUZE bottle trimesh and put it in a scene
fuze_trimesh = trimesh.load('pyrender/examples/models/fuze.obj')
mesh = pyrender.Mesh.from_trimesh(fuze_trimesh)
scene = pyrender.Scene()
scene.add(mesh)
# Set up the camera -- z-axis away from the scene, x-axis right, y-axis up
camera = pyrender.PerspectiveCamera(yfov=np.pi / 3.0)
s = np.sqrt(2)/2
camera_pose = np.array([
[0.0, -s, s, 0.3],
[1.0, 0.0, 0.0, 0.0],
[0.0, s, s, 0.35],
[0.0, 0.0, 0.0, 1.0],
])
scene.add(camera, pose=camera_pose)
# Set up the light -- a single spot light in the same spot as the camera
light = pyrender.SpotLight(color=np.ones(3), intensity=3.0,
innerConeAngle=np.pi/16.0)
scene.add(light, pose=camera_pose)
# Render the scene
r = pyrender.OffscreenRenderer(640, 480)
color, depth = r.render(scene)
# Show the images
import matplotlib.pyplot as plt
plt.figure()
plt.subplot(1,2,1)
plt.axis('off')
plt.imshow(color)
plt.subplot(1,2,2)
plt.axis('off')
plt.imshow(depth, cmap=plt.cm.gray_r)
plt.show()
When I run this code to generate my images. I got this error:
--------------------------------------------------------------------------
OSError Traceback (most recent call last)
C:\Anaconda3\lib\site-packages\OpenGL\platform\egl.py in EGL(self)
69 'EGL',
---> 70 mode=ctypes.RTLD_GLOBAL
71 )
C:\Anaconda3\lib\site-packages\OpenGL\platform\ctypesloader.py in loadLibrary(dllType, name, mode)
44 try:
---> 45 return dllType( name, mode )
46 except Exception as err:
C:\Anaconda3\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
347 if handle is None:
--> 348 self._handle = _dlopen(self._name, mode)
349 else:
OSError: [WinError 126] Le module spécifié est introuvable
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
<ipython-input-1-e86166a3612b> in <module>()
4 import numpy as np
5 import trimesh
----> 6 import pyrender
7
8 # Load the FUZE bottle trimesh and put it in a scene
C:\Anaconda3\lib\site-packages\pyrender\__init__.py in <module>()
1 from .camera import (Camera, PerspectiveCamera, OrthographicCamera,
2 IntrinsicsCamera)
----> 3 from .light import Light, PointLight, DirectionalLight, SpotLight
4 from .sampler import Sampler
5 from .texture import Texture
C:\Anaconda3\lib\site-packages\pyrender\light.py in <module>()
9
10 from .utils import format_color_vector
---> 11 from .texture import Texture
12 from .constants import SHADOW_TEX_SZ
13 from .camera import OrthographicCamera, PerspectiveCamera
C:\Anaconda3\lib\site-packages\pyrender\texture.py in <module>()
6 import numpy as np
7
----> 8 from OpenGL.GL import *
9
10 from .utils import format_texture_source
C:\Anaconda3\lib\site-packages\OpenGL\GL\__init__.py in <module>()
1 """OpenGL.GL, the core GL library and extensions to it"""
2 # early import of our modules to prevent import loops...
----> 3 from OpenGL import error as _error
4 from OpenGL.GL.VERSION.GL_1_1 import *
5 from OpenGL.GL.pointers import *
C:\Anaconda3\lib\site-packages\OpenGL\error.py in <module>()
10 import logging
11 _log = logging.getLogger( 'OpenGL.error' )
---> 12 from OpenGL import platform, _configflags
13 from ctypes import ArgumentError
14 __all__ = (
C:\Anaconda3\lib\site-packages\OpenGL\platform\__init__.py in <module>()
33 return plugin
34
---> 35 _load()
36
37 def types(resultType,*argTypes):
C:\Anaconda3\lib\site-packages\OpenGL\platform\__init__.py in _load()
30
31 # install into the platform module's namespace now
---> 32 plugin.install(globals())
33 return plugin
34
C:\Anaconda3\lib\site-packages\OpenGL\platform\baseplatform.py in install(self, namespace)
90 """Install this platform instance into the platform module"""
91 for name in self.EXPORTED_NAMES:
---> 92 namespace[ name ] = getattr(self,name,None)
93 namespace['PLATFORM'] = self
94 return self
C:\Anaconda3\lib\site-packages\OpenGL\platform\baseplatform.py in __get__(self, obj, cls)
12 self.fget = function
13 def __get__( self, obj, cls ):
---> 14 value = self.fget( obj )
15 setattr( obj, self.fget.__name__, value)
16 return value
C:\Anaconda3\lib\site-packages\OpenGL\platform\egl.py in GetCurrentContext(self)
91 @baseplatform.lazy_property
92 def GetCurrentContext( self ):
---> 93 return self.EGL.eglGetCurrentContext
C:\Anaconda3\lib\site-packages\OpenGL\platform\baseplatform.py in __get__(self, obj, cls)
12 self.fget = function
13 def __get__( self, obj, cls ):
---> 14 value = self.fget( obj )
15 setattr( obj, self.fget.__name__, value)
16 return value
C:\Anaconda3\lib\site-packages\OpenGL\platform\egl.py in EGL(self)
71 )
72 except OSError as err:
---> 73 raise ImportError("Unable to load EGL library", *err.args)
74 @baseplatform.lazy_property
75 def getExtensionProcedure( self ):
ImportError: ('Unable to load EGL library', 22, 'Le module spécifié est introuvable', None, 126, None, 'EGL', None)
I installed all necessary modules in python such as pyrender
module and I didn't understand where the problem is .
Here the link of pyrender
work : link.
Upvotes: 2
Views: 13615
Reputation: 63
If you are on windows, simply comment out the line where you specify the PYOPENGL_PLATFORM.
Upvotes: 2
Reputation: 53
In my case(Ubuntu 18.04, pyrender==1.43, python==3.7.8),
sudo apt-get install libosmesa6-dev
sudo apt-get install freeglut3-dev
solved the problem. Maybe the first line is not necessary.
Upvotes: 2
Reputation: 99
you can try
apt-get install libglfw3-dev libgles2-mesa-dev
and this solved my problem. Hope it helps for you.
Upvotes: 4