Python Kinect视频频道设置

Python Kinect视频频道设置,python,kinect,pykinect,Python,Kinect,Pykinect,我写了一个程序,在pygame屏幕上显示kinect视频频道 import thread import pygame import easygui from pykinect import nui DEPTH_WINSIZE = (640, 480) screen_lock = thread.allocate() screen = None tmp_s = pygame.Surface(DEPTH_WINSIZE, 0, 16) s=None def video_frame_ready(

我写了一个程序,在pygame屏幕上显示kinect视频频道

import thread
import pygame
import easygui
from pykinect import nui

DEPTH_WINSIZE = (640, 480)

screen_lock = thread.allocate()
screen = None

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

s=None
def video_frame_ready(frame):
    with screen_lock:
        frame.image.copy_bits(tmp_s._pixels_address)
        arr2d = (pygame.surfarray.pixels2d(tmp_s) >> 7) & 255
        pygame.surfarray.blit_array(screen, arr2d)

        pygame.display.update()

def main():
    """Initialize and run the game"""
    pygame.init()
    global s
    s=0
    global arr
    arr = []

    # Initialize PyGame
    global screen
    screen = pygame.display.set_mode(DEPTH_WINSIZE, 0, 8)
    screen.set_palette(tuple([(i, i, i) for i in range (256)]))
    pygame.display.set_caption("PyKinect Depth Map Example")

    angle = 0
    with nui.Runtime() as kinect:
        kinect.video_frame_ready += video_frame_ready
        kinect.video_stream.open(nui.ImageStreamType.Video, 2, nui.ImageResolution.Resolution640x480, nui.ImageType.Color)        
        # Main game loop
        while (True):
            event = pygame.event.wait()

            if (event == pygame.QUIT):
                break
if (__name__ == "__main__"):
    main()
在frame.image.copy_bits(tmp_s._pixels_address)行,它给出了一个错误:

Unhandled exception in thread started by <bound method Runtime._event_thread of <pykinect.nui.Runtime object at 0x03FDB0D0>>
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\pykinect-1.0-py2.7.egg\pykinect\nui\__init__.py", line 196, in _event_thread
    self.video_frame_ready.fire(depth_frame)     
  File "C:\Python27\lib\site-packages\pykinect-1.0-py2.7.egg\pykinect\nui\__init__.py", line 426, in fire
    handler(*args)
  File "C:/Users/navid/Desktop/Kinect_Project/Kinect_Color_Video.py", line 16, in video_frame_ready
    frame.image.copy_bits(tmp_s._pixels_address)
  File "C:\Python27\lib\site-packages\pykinect-1.0-py2.7.egg\pykinect\nui\structs.py", line 133, in copy_bits
    ctypes.memmove(dest, rect.bits, desc.height * rect.pitch)
WindowsError: exception: access violation writing 0x0A80C000
由启动的线程中未处理的异常 回溯(最近一次呼叫最后一次): 文件“C:\Python27\lib\site packages\pykinect-1.0-py2.7.egg\pykinect\nui\\uuuu init\uuu.py”,第196行,在事件线程中 自拍。视频帧准备就绪。开火(深度帧) 文件“C:\Python27\lib\site packages\pykinect-1.0-py2.7.egg\pykinect\nui\\uuu init\uu.py”,第426行,着火 处理程序(*args) 文件“C:/Users/navid/Desktop/Kinect\u Project/Kinect\u Color\u Video.py”,第16行,视频帧中 帧、图像、复制位(tmp像素、地址) 文件“C:\Python27\lib\site packages\pykinect-1.0-py2.7.egg\pykinect\nui\structs.py”,第133行,拷贝位 ctypes.memmove(目标、矩形位、描述高度*矩形节距) WindowsError:异常:访问冲突写入0x0A80C000 有办法解决这个问题吗? 非常感谢您的帮助。

试试以下方法:

import pygame
import easygui
from pykinect import nui

VIDEO_WINSIZE = (640, 480)

screen = None

s=None
def video_frame_ready(frame):
    frame.image.copy_bits(screen._pixels_address)
    pygame.display.update()

def main():
    """Initialize and run the game"""
    pygame.init()
    global s
    s=0
    global arr
    arr = []

    # Initialize PyGame
    global screen
    screen = pygame.display.set_mode(VIDEO_WINSIZE, 0, 32)

    pygame.display.set_caption("PyKinect Video Example")

    angle = 0
    with nui.Runtime() as kinect:
        kinect.video_frame_ready += video_frame_ready
        kinect.video_stream.open(nui.ImageStreamType.Video, 2, nui.ImageResolution.Resolution640x480, nui.ImageType.Color)        
        # Main game loop
        while (True):
            event = pygame.event.wait()

            if (event == pygame.QUIT):
                break
if (__name__ == "__main__"):
    main()