Dockerfile:
FROM python:3.8.12-slim-buster
RUN apt-get update && apt-get install -y python-opengl wget
RUN pip install mesh-to-sdf建立这个码头形象。让我们把它命名为test。
docker build -t test .从这个映像运行并执行一个容器。
docker run --name test -d -t test
docker exec -it test bash在容器中,创建以下2个文件,mesh.obj和convert.py。您可以使用以下命令下载它们:
wget https://gist.githubusercontent.com/zshyang/9f4b18dea65ac5bba61a7fc2bbd98aa4/raw/9e681e2f9fa1bb3682fe8c95d8341b5b1e0f798a/mesh.obj
wget https://gist.githubusercontent.com/zshyang/4cf826bc16c05038c2b4529422b82484/raw/4127b8a0d443e0f257a162a9b3278595ac94ea76/convert.pyf 1 2 3
v 1 1 1
v 1 2 3
v 1 9 0import trimesh
import mesh_to_sdf
mesh = trimesh.load('mesh.obj')
mesh_to_sdf.sample_sdf_near_surface(mesh, number_of_points = 500000, surface_point_method='scan', sign_method='normal', scan_count=100, scan_resolution=400, sample_point_count=10000000, normal_sample_count=11, min_size=0, return_gradients=False)然后,通过运行python convert.py,我得到以下错误。
Traceback (most recent call last):
File "convert.py", line 4, in <module>
mesh_to_sdf.sample_sdf_near_surface(mesh, number_of_points = 500000, surface_point_method='scan', sign_method='normal', scan_count=100, scan_resolution=400, sample_point_count=10000000, normal_sample_count=11, min_size=0, return_gradients=False)
File "/usr/local/lib/python3.8/site-packages/mesh_to_sdf/__init__.py", line 59, in sample_sdf_near_surface
surface_point_cloud = get_surface_point_cloud(mesh, surface_point_method, 1, scan_count, scan_resolution, sample_point_count, calculate_normals=sign_method=='normal' or return_gradients)
File "/usr/local/lib/python3.8/site-packages/mesh_to_sdf/__init__.py", line 17, in get_surface_point_cloud
return surface_point_cloud.create_from_scans(mesh, bounding_radius=bounding_radius, scan_count=scan_count, scan_resolution=scan_resolution, calculate_normals=calculate_normals)
File "/usr/local/lib/python3.8/site-packages/mesh_to_sdf/surface_point_cloud.py", line 162, in create_from_scans
scans.append(Scan(mesh,
File "/usr/local/lib/python3.8/site-packages/mesh_to_sdf/scan.py", line 61, in __init__
color, depth = render_normal_and_depth_buffers(mesh, camera, self.camera_transform, resolution)
File "/usr/local/lib/python3.8/site-packages/mesh_to_sdf/pyrender_wrapper.py", line 58, in render_normal_and_depth_buffers
renderer = pyrender.OffscreenRenderer(resolution, resolution)
File "/usr/local/lib/python3.8/site-packages/pyrender/offscreen.py", line 31, in __init__
self._create()
File "/usr/local/lib/python3.8/site-packages/pyrender/offscreen.py", line 149, in _create
self._platform.init_context()
File "/usr/local/lib/python3.8/site-packages/pyrender/platforms/pyglet_platform.py", line 50, in init_context
self._window = pyglet.window.Window(config=conf, visible=False,
File "/usr/local/lib/python3.8/site-packages/pyglet/window/xlib/__init__.py", line 171, in __init__
super(XlibWindow, self).__init__(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/pyglet/window/__init__.py", line 590, in __init__
display = pyglet.canvas.get_display()
File "/usr/local/lib/python3.8/site-packages/pyglet/canvas/__init__.py", line 94, in get_display
return Display()
File "/usr/local/lib/python3.8/site-packages/pyglet/canvas/xlib.py", line 123, in __init__
raise NoSuchDisplayException('Cannot connect to "%s"' % name)
pyglet.canvas.xlib.NoSuchDisplayException: Cannot connect to "None"你知道怎么解决这个问题吗?谢谢!
发布于 2022-02-11 03:32:00
要通过特定的错误,您必须设置一个显示,以供GL使用。一个简单的方法是使用Xvfb。
将这一行添加到Dockerfile中:
RUN apt-get install -y xvfb然后,在容器中,在运行脚本之前,运行以下命令来创建屏幕外显示缓冲区,并将display env var设置为指向它:
Xvfb :1 -screen 0 1024x768x24 -ac +extension GLX +render -noreset &> xvfb.log &
export DISPLAY=:1当我这样做,然后运行您的代码,我得到一个新的错误:
pyglet.gl.ContextException: Could not create GL context我做了一些谷歌搜索,尝试了一些事情,但找不到一个简单的方法来克服这个错误。我在这个错误消息周围发现的线程谈到了两件事:库代码中的bug和GL版本。我建议,如果/当你收到错误信息时,你搜索它,看看你能得到什么,看看你下一步需要做什么。
祝你好运!
https://stackoverflow.com/questions/71074766
复制相似问题