2014-06-13 15 views
1

버전 2.1b1의 get_next_frame()에서 TODO에 대해/도움PyKinect는 윈도우 7에, 나는 (Micosoft 비주얼 스튜디오를 사용하지 않고) Kynect + 파이썬 함께 일하고

사람은을 사용하지 않고 키 넥트에서 프레임을 얻는 방법을 알고 있나요 이벤트 루프?

내가 위의 기능 평

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) 

초기화하기 누이 PyKinect// 이 방법으로 다스 려하고하는 것은 내가 필요하고 아직 구현되지 않은 것입니다. 이벤트 루프를 사용하지 않고 필요에 따라 프레임을 가져와야합니다.

어떻게하면됩니까?

나는 다음과 같은 환경과 버전을 사용하고 있습니다 :

  • 파이썬 2.7.2
  • PyKinect 2.1b1
  • (XBOX의 V1에서)
  • 키 넥트 센서
  • 키 넥트 SDK 1.8
  • 윈도우 7

답변

0

"on dem"에서 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을 가정 해 봅시다). 당신이 깊이 데이터를 사용해야하는 경우, 당신은 전역 변수 때마다 참조 할 수 있습니다,

import threading 
import pygame 

DEPTH_WINSIZE = 320,240 
tmp_s = pygame.Surface(DEPTH_WINSIZE, 0, 16) 

depth_data = None 
depth_lock = threading.Lock() 

def update_depth_data(new_depth_data): 
    global depth_data 
    depth_lock.acquire() 
    depth_data = new_depth_data 
    depth_lock.release() 

#based on https://bitbucket.org/snippets/VitoGentile/Eoze 
def depth_frame_ready(frame): 
    # Copy raw data in a temp surface 
    frame.image.copy_bits(tmp_s._pixels_address) 

    update_depth_data((pygame.surfarray.pixels2d(tmp_s) >> 3) & 4095) 

이제 당신은 또한 (쓰기와 읽기를 동시에 방지하기 위해 간단한 Lock)을 읽고 그 변수를 작성하는 동기화 메커니즘이 필요합니다 네가 원해.

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

update_depth_data() 기능에서 수행대로 액세스를 동기화하는 depth_lock을 사용해야합니다.