我有我编写的这个程序,用于在 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
有没有办法解决这个问题?任何帮助深表感谢。