"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
을 사용해야합니다.