PyKinect帮助/关于2.1b1版本中的TODO get_next_frame()

2024-09-28 23:23:30 发布

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

我正在Windows7上使用Kynect+Python(不使用Micosoft visualstudio)。在

有人知道如何在不使用事件循环的情况下从Kinect获取帧吗?在

我指的是PyKinect/nui/init.py的这种方法

def get_next_frame(self, milliseconds_to_wait = 0):
# TODO: Allow user to provide a NUI_IMAGE_FRAME ?
return self.runtime._nui.NuiImageStreamGetNextFrame(self._stream, milliseconds_to_wait)

上面的功能正是我需要的,它还没有实现。我需要它来按需获取帧(不使用事件循环)。在

我该怎么做?在

我正在使用以下环境和版本:

  • Python 2.7.2
  • PyKinect 2.1b1
  • Kinect传感器(来自XBOX v1)
  • Kinect SDK 1.8版
  • Windows 7系统

Tags: topyselfinit事件情况waitvisualstudio
1条回答
网友
1楼 · 发布于 2024-09-28 23:23:30

您无法“按需”获取RGB、深度或骨架帧。Kinect数据由事件提供,因此您必须使用它们来获取数据。在

要解决这个基于事件的系统,您唯一能做的就是将数据保存在一个全局变量中,然后在需要时读取该变量。在

例如,假设您将一个名为depth_frame_ready的函数与深度数据相关的事件相关联:

from pykinect import nui

with nui.Runtime() as kinect:
    kinect.depth_frame_ready += depth_frame_ready   
    kinect.depth_stream.open(nui.ImageStreamType.Depth, 2, nui.ImageResolution.Resolution320x240, nui.ImageType.Depth)

您可以编写depth_frame_ready函数来保存全局变量上的数据(比如depth_data)。您还需要一个同步机制来读写该变量(一个简单的Lock来避免同时读写):

^{pr2}$

现在,如果需要使用深度数据,可以随时引用全局变量。在

global depth_data
if depth_data is not None:
    #read your data

记住使用depth_lock来同步访问,就像在update_depth_data()函数中所做的那样。在

相关问题 更多 >