2

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

この問題を解決する方法はありますか? どんな助けでも大歓迎です。

4

1 に答える 1

0

これを試して:

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()
于 2016-01-17T15:18:46.977 に答える