错误描述

在跑 VIBE 时,使用了不带显示器的 Centos 服务器, 在使用 pyrender 进行 offscreen 渲染时报错 OpenGL.error.GLError: GLError(err = 12296,,具体如下:

Traceback (most recent call last):
  File "demo.py", line 416, in <module>
    main(args)
  File "demo.py", line 278, in main
    renderer = Renderer(resolution=(orig_width, orig_height), orig_img=True, wireframe=args.wireframe)
  File "***/VIBE/lib/utils/renderer.py", line 60, in __init__
    point_size=1.0
  File "***/anaconda3/envs/vibe-env/lib/python3.7/site-packages/pyrender/offscreen.py", line 31, in __init__
    self._create()
  File "***/anaconda3/envs/vibe-env/lib/python3.7/site-packages/pyrender/offscreen.py", line 134, in _create
    self._platform.init_context()
  File "***/anaconda3/envs/vibe-env/lib/python3.7/site-packages/pyrender/platforms/egl.py", line 177, in init_context
    assert eglInitialize(self._egl_display, major, minor)
  File "***/anaconda3/envs/vibe-env/lib/python3.7/site-packages/OpenGL/platform/baseplatform.py", line 409, in __call__
    return self( *args, **named )
  File "***/anaconda3/envs/vibe-env/lib/python3.7/site-packages/OpenGL/error.py", line 232, in glCheckError
    baseOperation = baseOperation,
OpenGL.error.GLError: GLError(
        err = 12296,
        baseOperation = eglInitialize,
        cArguments = (
                <OpenGL._opaque.EGLDisplay_pointer object at 0x7f883a03a170>,
                c_long(0),
                c_long(0),
        ),
        result = 0
)

解决方案

  1. Ubuntu 可参考 https://pyrender.readthedocs.io/en/latest/install/index.html#installmesa 使用 OSMesa 来进行 offscreen render
  2. 可更方便使用 ·conda· 来安装 OSMesa,如下:
    conda install osmesa
    

注意:安装好 OSMesa 之后,重新安装 PyOpenGL,否则仍会报错,如下:

pip uninstall pyopengl
git clone https://github.com/mmatl/pyopengl.git
pip install ./pyopengl

在运行脚本之前指定 PYOPENGL_PLATFORMosmesa 即可,如下:

# demp.py
import os
# os.environ['PYOPENGL_PLATFORM'] = 'egl'
os.environ['PYOPENGL_PLATFORM'] = 'osmesa'

注意os.environ['PYOPENGL_PLATFORM'] = 'osmesa' 最好紧跟在 import os 后面,确保在使用 render 之前将 PYOPENGL_PLATFORM 更改为 osmesa,也可以在具体使用 render 之前显式指定 os.environ['PYOPENGL_PLATFORM'] = 'osmesa'

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐