本文整理汇总了Python中OpenGL.GL.glReadPixels方法的典型用法代码示例。如果您正苦于以下问题:Python GL.glReadPixels方法的具体用法?Python GL.glReadPixels怎么用?Python GL.glReadPixels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenGL.GL
的用法示例。
在下文中一共展示了GL.glReadPixels方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_fbo_color_rgba32f
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glReadPixels [as 别名]
def read_fbo_color_rgba32f(fbo):
"""
Read the color attachment from a FBO, assuming it is GL_RGBA_32F.
# Ref: https://github.com/julienr/vertex_visibility/blob/master/depth.py
"""
h, w = fbo.color_buffer.shape[:2]
x, y = 0, 0
im = gl.glReadPixels(x, y, w, h, gl.GL_RGBA, gl.GL_FLOAT)
im = np.frombuffer(im, np.float32)
im.shape = h, w, 4
im = im[::-1, :]
return im
#-------------------------------------------------------------------------------
# Ref: https://github.com/vispy/vispy/blob/master/examples/demo/gloo/offscreen.py
示例2: finish
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glReadPixels [as 别名]
def finish(self):
im = gl.glReadPixels(0, 0, self.size[0], self.size[1], gl.GL_RGB, gl.GL_FLOAT)
rgb = np.copy(np.frombuffer(im, np.float32)).reshape(self.shape+(3,))[::-1, :] # Read buffer and flip Y
im = gl.glReadPixels(0, 0, self.size[0], self.size[1], gl.GL_DEPTH_COMPONENT, gl.GL_FLOAT)
dep = np.copy(np.frombuffer(im, np.float32)).reshape(self.shape+(1,))[::-1, :] # Read buffer and flip Y
# Convert z-buffer to depth map
mult = (self.clip_near*self.clip_far)/(self.clip_near-self.clip_far)
addi = self.clip_far/(self.clip_near-self.clip_far)
bg = dep == 1
dep = mult/(dep + addi)
dep[bg] = 0
return rgb, np.squeeze(dep)
示例3: _blockUnderCursor
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glReadPixels [as 别名]
def _blockUnderCursor(self, center=False):
"""
returns a point in 3d space that was determined by
reading the depth buffer value
"""
try:
GL.glReadBuffer(GL.GL_BACK)
except Exception:
logging.exception('Exception during glReadBuffer')
ws = self.root.size
if center:
x, y = ws
x //= 2
y //= 2
else:
x, y = mouse.get_pos()
if (x < 0 or y < 0 or x >= ws[0] or
y >= ws[1]):
return 0, 0, 0
y = ws[1] - y
try:
pixel = GL.glReadPixels(x, y, 1, 1, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT)
newpoint = unproject(x, y, pixel[0])
except Exception:
return 0, 0, 0
return newpoint
示例4: OnCaptureResult
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glReadPixels [as 别名]
def OnCaptureResult(render_path, img_path, width, height, true_height, if_vis, render_type='rgb'):
if render_type == 'rgb':
rgb_img = GL.glReadPixels(0, 0, width, height, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, outputType=None)[::-1, :, :][
height - true_height:, :, :]
if if_vis:
plt.imshow(rgb_img)
plt.axis('off')
plt.savefig(img_path, bbox_inches='tight')
plt.close()
# print render_path
np.save(render_path, rgb_img)
return rgb_img
elif render_type == 'segmentation':
segment = GL.glReadPixels(0, 0, width, height, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, outputType=None)[::-1, :, :][
height - true_height:, :, 0]
if if_vis:
plt.imshow(segment, vmin=0, vmax=38)
# plt.colorbar()
plt.axis('off')
plt.savefig(img_path, bbox_inches='tight')
plt.close()
np.save(render_path, segment)
return segment
elif render_type == 'normal':
normal = GL.glReadPixels(0, 0, width, height, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, outputType=None)[::-1, :, :][
height - true_height:, :, :]
if if_vis:
plt.imshow(normal)
plt.axis('off')
plt.savefig(img_path, bbox_inches='tight')
plt.close()
np.save(render_path, normal)
return normal
elif render_type == 'depth':
data = GL.glReadPixels(0, 0, width, height, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT,
outputType=None) # read projected pixel info
capturedImage = data
for i in range(width):
for j in range(height):
if capturedImage[i][j] == 1.0:
capturedImage[i][j] = 20
else:
far = FAR
near = 0.1
clip_z = (capturedImage[i][j] - 0.5) * 2.0
world_z = 2 * far * near / (clip_z * (far - near) - (far + near))
capturedImage[i][j] = -world_z # -z#
depth = capturedImage[::-1, :][height - true_height:, :]
if if_vis:
fig = plt.figure()
ii = plt.imshow(depth, interpolation='nearest')
# fig.colorbar(ii)
plt.axis('off')
plt.savefig(img_path, bbox_inches='tight')
plt.close()
np.save(render_path, depth)
scipy.io.savemat(render_path + '.mat', mdict={'depth': depth})
return depth