我想获取从 3D 对象的不同视图中捕获的深度缓冲区图像。为此,pyOpenGL
我使用以下代码
def get_depth(LookAt_x, LookAt_y, LookAt_z)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
gluLookAt(LookAt_x, LookAt_y, LookAt_z, 0, 0, 0, 0, 1, 0)
draw_object() // glBegin() for ... glvertex3f........ glEnd()
glReadBuffer(GL_FRONT)
depth_image = glReadPixels(0, 0, image_size, image_size, GL_DEPTH_COMPONENT, GL_FLOAT)
def draw_object(self):
glBegin(GL_TRIANGLES)
for tri in self.get_triangles():
glNormal3f(tri.normal.x,tri.normal.y,tri.normal.z)
glVertex3f(tri.points[0].x,tri.points[0].y,tri.points[0].z)
glVertex3f(tri.points[1].x,tri.points[1].y,tri.points[1].z)
glVertex3f(tri.points[2].x,tri.points[2].y,tri.points[2].z)
glEnd()
代码链接:https ://www.linux.com/blog/python-stl-model-loading-and-display-opengl
我用不同的观点来调用这个函数LookAt_x
, LookAt_y
, LookAt_z
. 但是,每次绘制对象都需要花费太多时间。
有没有一种可能的方法,一旦绘制了对象,只需改变视点即可获得深度图像?