PyKinect (Yep, Python and Kinect, in Visual Studio yet!)

Description

Credit for today's entry goes to Develop with Python in Visual Studio, connect with Kinect and Excel. I don't follow Python news much and so might have missing this if it wasn't for Dan's post.

Not only do does this highlight the latest version of the Python Tools for Visual Studio release, but shows off using Python to develop Kinect for Windows SDK games and applications. 

PyKinect – write Kinect games using Python!

We are very excited to announce PyKinect with PTVS [Python Tools for Visual Studio] 1.1. PyKinect enables writing awesome games and interfaces using Python:

Prerequisites:

Installation:

Assuming you’ve already installed PTVS & a CPython interpreter, install PyGame, Kinect SDK and PyKinect (order doesn’t matter). To verify the installation, you can check: Tools/Python Tools/Samples/PyKinect -- you should be able use this to install PyKinect into a 32-bit Python distribution:

...

Project Information URL: http://pytools.codeplex.com/wikipage?title=PyKinect

Project Download URL: http://pytools.codeplex.com/releases

Project Source URL: http://pytools.codeplex.com/SourceControl/list/changesets

image

image

pykinect.install_6

if __name__ == '__main__':
    full_screen = False
    draw_skeleton = True
    video_display = False

    screen_lock = thread.allocate()

    screen = pygame.display.set_mode(DEPTH_WINSIZE,0,16)    
    pygame.display.set_caption('Python Kinect Demo')
    skeletons = None
    screen.fill(THECOLORS["black"])

    kinect = nui.Runtime()
    kinect.skeleton_engine.enabled = True
    def post_frame(frame):
        try:
            pygame.event.post(pygame.event.Event(KINECTEVENT, skeletons = frame.SkeletonData))
        except:
            # event queue full
            pass

    kinect.skeleton_frame_ready += post_frame
    
    kinect.depth_frame_ready += depth_frame_ready    
    kinect.video_frame_ready += video_frame_ready    
    
    kinect.video_stream.open(nui.ImageStreamType.Video, 2, nui.ImageResolution.Resolution640x480, nui.ImageType.Color)
    kinect.depth_stream.open(nui.ImageStreamType.Depth, 2, nui.ImageResolution.Resolution320x240, nui.ImageType.Depth)

    print('Controls: ')
    print('     d - Switch to depth view')
    print('     v - Switch to video view')
    print('     s - Toggle displaing of the skeleton')
    print('     u - Increase elevation angle')
    print('     j - Decrease elevation angle')

    # main game loop
    done = False

    while not done:
        e = pygame.event.wait()
        dispInfo = pygame.display.Info()
        if e.type == pygame.QUIT:
            done = True
            break
        elif e.type == KINECTEVENT:
            skeletons = e.skeletons
            if draw_skeleton:
                draw_skeletons(skeletons)
                pygame.display.update()
        elif e.type == KEYDOWN:
            if e.key == K_ESCAPE:
                done = True
                break
            elif e.key == K_d:
                with screen_lock:
                    screen = pygame.display.set_mode(DEPTH_WINSIZE,0,16)
                    video_display = False
            elif e.key == K_v:
                with screen_lock:
                    screen = pygame.display.set_mode(VIDEO_WINSIZE,0,32)    
                    video_display = True
            elif e.key == K_s:
                draw_skeleton = not draw_skeleton
            elif e.key == K_u:
                kinect.camera.elevation_angle = kinect.camera.elevation_angle + 2
            elif e.key == K_j:
                kinect.camera.elevation_angle = kinect.camera.elevation_angle - 2
            elif e.key == K_x:
                kinect.camera.elevation_angle = 2

The Discussion

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to send us feedback you can Contact Us.