首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Kinect视频频道设置Python

Kinect视频频道设置Python
EN

Stack Overflow用户
提问于 2016-01-17 12:52:59
回答 1查看 702关注 0票数 2

我有一个程序,我写了一个游戏屏幕上显示kinect视频频道。

代码语言:javascript
复制
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)行中,它给出了一个错误:

代码语言:javascript
复制
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

有办法解决这个问题吗?任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-17 15:18:46

试试这个:

代码语言:javascript
复制
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()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34838525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档