pykinect2深度帧被截断

2024-04-23 06:20:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用PyKinect2模块从Kinect v2设备获取深度帧。我遵循了here提供的示例。我可以看到深度帧,但是它们出现在PyGame窗口中被截断,尽管帧的大小应该是512x424。在

depth_frame

我使用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()

Tags: 模块self示例targetgethereaddressctypes
2条回答

首先,您必须将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以获取深度帧宽度和高度:

^{pr2}$

最后,画出深度框架,如@双君建议:

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()

我没什么好评论的。所以我写在这里。 我想你需要3个通道来填充内存到所需的长度。 试试这个

f8=np.uint8(frame.clip(1,4000)/16.)    
frame8bit=np.dstack((f8,f8,f8))

然后memmove from frame8bit而不是原来的frame。在

相关问题 更多 >