Kinect视频频道设置Python

2024-06-07 21:09:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我写了一个程序,在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_位(tmp_s.\u pixels_address)行,它给我一个错误:

^{pr2}$

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


Tags: importmainvideodisplayscreenglobalframepygame
1条回答
网友
1楼 · 发布于 2024-06-07 21:09:17

试试这个:

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()

相关问题 更多 >

    热门问题