我正在尝试使用PyKinect2模块从Kinect v2设备获取深度帧。我遵循了here提供的示例。我可以看到深度帧,但它们出现在截断的PyGame窗口中,尽管帧的大小是512x424,这是它应该的大小。
我使用PyKinect2提供的get_last_depth_frame()方法,并使用以下代码将其绘制在表面上。
def draw_depth_frame(self, frame, target_surface):
target_surface.lock()
address = self._kinect.surface_as_array(target_surface.get_buffer())
ctypes.memmove(address, frame.ctypes.data, frame.size)
del address
target_surface.unlock()发布于 2018-08-02 09:46:52
我没有什么好评论的。所以我把它写在这里。我认为你需要3个通道来填充内存到所需的长度。尝尝这个
f8=np.uint8(frame.clip(1,4000)/16.)
frame8bit=np.dstack((f8,f8,f8))然后从frame8bit中移动,而不是从原始框架中。
发布于 2018-09-01 20:07:43
首先,您必须将Surface大小更改为24位:
在__init__(self)函数中:
self._depth_frame_surface = pygame.Surface((self._kinect.depth_frame_desc.Width,
self._kinect.depth_frame_desc.Height),
0, 24)然后,您应该更改self._screen以获取深度、框架宽度和高度:
self._screen = pygame.display.set_mode((self._kinect.depth_frame_desc.Width,
self._kinect.depth_frame_desc.Height), pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.RESIZABLE,
32)最后,像@Shuangjun建议的那样绘制深度框:
def draw_depth_frame(self, frame, target_surface):
target_surface.lock()
f8 = np.uint8(frame.clip(1, 4000) / 16.)
frame8bit = np.dstack((f8, f8, f8))
address = self._kinect.surface_as_array(target_surface.get_buffer())
ctypes.memmove(address, frame8bit.ctypes.data, frame8bit.size)
del address
target_surface.unlock()https://stackoverflow.com/questions/47217691
复制相似问题