none
Kinect with Python RRS feed

  • Question

  • Hello, people.

    I am programming a software with Python (using the library PyKinect and Visual for to build 3D objects) for Kinect. My objective is to build a code for to do the joint of right hand to move a little sphere. But, I did not get success. 

    I did just the ball to walk for a small time step, and after the ball stops.

    Someone could help me? (Sorry for my bad English)

    from visual import *
    import pykinect
    from pykinect import nui
    from pykinect.nui import JointId
    
    class Skeleton:
        """Kinect skeleton represented as a VPython frame.
        """
    
        def __init__(self, f):
            """Create a skeleton in the given VPython frame f.
            """
            self.frame = f
            self.joints = [sphere(frame=f, radius=0.08, color=color.yellow)
                           for i in range(20)]
            self.joints[3].radius = 0.125
            self.bones = [cylinder(frame=f, radius=0.05, color=color.yellow)
                          for bone in _bone_ids]
            #MÃO DIREITA
            self.rightHand = self.joints[11]
    
        def update(self):
            """Update the skeleton joint positions in the depth sensor frame.
    
            Return true iff the most recent sensor frame contained a tracked
            skeleton.
            """
            updated = False
            for skeleton in _kinect.skeleton_engine.get_next_frame().SkeletonData:
                if skeleton.eTrackingState == nui.SkeletonTrackingState.TRACKED:
    
                    # Move the joints.
                    for joint, p in zip(self.joints, skeleton.SkeletonPositions):
                        joint.pos = (p.x, p.y, p.z)
    
                    # Move the bones.
                    for bone, bone_id in zip(self.bones, _bone_ids):
                        p1, p2 = [self.joints[id].pos for id in bone_id]
                        bone.pos = p1
                        bone.axis = p2 - p1
                    updated = True
            return updated
    
    def draw_sensor(f):
        """Draw 3D model of the Kinect sensor.
    
        Draw the sensor in the given (and returned) VPython frame f, with
        the depth sensor frame aligned with f.
        """
        box(frame=f, pos=(0, 0, 0), length=0.2794, height=0.0381, width=0.0635,
            color=color.blue)
        cylinder(frame=f, pos=(0, -0.05715, 0), axis=(0, 0.0127, 0), radius=0.0381,
                 color=color.blue)
        cone(frame=f, pos=(0, -0.04445, 0), axis=(0, 0.01905, 0), radius=0.0381,
             color=color.blue)
        cylinder(frame=f, pos=(0, -0.05715, 0), axis=(0, 0.0381, 0), radius=0.0127,
                 color=color.blue)
        cylinder(frame=f, pos=(-0.0635, 0, 0.03175), axis=(0, 0, 0.003),
                 radius=0.00635, color=color.red)
        cylinder(frame=f, pos=(-0.0127, 0, 0.03175), axis=(0, 0, 0.003),
                 radius=0.00635, color=color.red)
        cylinder(frame=f, pos=(0.0127, 0, 0.03175), axis=(0, 0, 0.003),
                 radius=0.00635, color=color.red)
        text(frame=f, text='KINECT', pos=(0.06985, -0.00635, 0.03175),
             align='center', height=0.0127, depth=0.003)
        return f
    
    # A bone is a cylinder connecting two joints, each specified by an id.
    _bone_ids = [[0, 1], [1, 2], [2, 3], [7, 6], [6, 5], [5, 4], [4, 2],
                 [2, 8], [8, 9], [9, 10], [10, 11], [15, 14], [14, 13], [13, 12],
                 [12, 0], [0, 16], [16, 17], [17, 18], [18, 19]]
    
    # Initialize and level the Kinect sensor.
    _kinect = nui.Runtime()
    _kinect.skeleton_engine.enabled = True
    _kinect.camera.elevation_angle = 0
    
    if __name__ == '__main__':
        draw_sensor(frame())
        skeleton = Skeleton(frame(visible=False))
        ball = sphere(radius=0.1, color=color.red, pos=(0.0,0.0,0.95))
        ball.velocity = 0.5
        t = 0.01
        while True:
            rate(30)
            skeleton.frame.visible = skeleton.update()
            if ((skeleton.rightHand.pos.x + skeleton.rightHand.radius <= ball.radius - ball.pos.x and skeleton.rightHand.x > ball.pos.x) or
                (skeleton.rightHand.pos.y + skeleton.rightHand.radius <= ball.radius - ball.pos.y and skeleton.rightHand.y > ball.pos.y) or
                (skeleton.rightHand.pos.z + skeleton.rightHand.radius <= ball.radius - ball.pos.z and skeleton.rightHand.z > ball.pos.z)):
    
                #bola.updateObject(bola.pos.x, bola.pos.y, bola.pos.z, skeleton.mao.pos.x, skeleton.mao.pos.y, skeleton.mao.pos.z)
                ball.pos.x = skeleton.rightHand.pos.x + ball.velocity * t
                ball.pos.y = skeleton.rightHand.pos.y + ball.velocity * t
                ball.pos.z = skeleton.rightHand.pos.z + ball.velocity * t
                print ball.pos.x
                t = t + 0.01
                
            else:
                print "The ball is static"
    
    
    
    
    
    
    
    
    
    
    
            
    


    Wednesday, February 12, 2014 2:05 PM

Answers

  • Support for that library will be provided by the developer of the plug-in for Python. There may be someone that could assist here, but you will have better luck engaging with the that developer.

    Carmine Sirignano - MSFT

    Wednesday, February 12, 2014 7:01 PM

All replies

  • Support for that library will be provided by the developer of the plug-in for Python. There may be someone that could assist here, but you will have better luck engaging with the that developer.

    Carmine Sirignano - MSFT

    Wednesday, February 12, 2014 7:01 PM
  • I've found the python google group helpful for other non Microsoft specific questions for the Kinect:

    https://groups.google.com/forum/#!forum/openkinect

    Here's also a link to some other awesome Kinect Resources I've found helpful:

    http://timmyreilly.azurewebsites.net/kinect-hackers-resources/

    Friday, December 4, 2015 10:58 PM