mapping an ellipse to a joint in kinect sdk 1.5

前端 未结 2 1997
孤独总比滥情好
孤独总比滥情好 2021-01-26 01:13

i want to map an ellipse to the hand joint.And the ellipse has to move as my hand joint will move.

Please provide me some reference links that help me in doing programs

2条回答
  •  佛祖请我去吃肉
    2021-01-26 01:28

    Basically somewhere in the code you will have a class to interact with Kinect SDK:

    private KinectSensor kinectSensor;
    

    You can initilazied KinectSensor this way:

    public void kinectInit()
    {
        KinectSensor.KinectSensors.StatusChanged += (object sender, StatusChangedEventArgs e) =>
        {
            if (e.Sensor == kinectSensor)
            {
                if (e.Status != KinectStatus.Connected)
                {
                    SetSensor(null);
                }
            }else if ((kinectSensor == null) && (e.Status == KinectStatus.Connected))
            {
                SetSensor(e.Sensor);
            }
        };
    
        foreach (var sensor in KinectSensor.KinectSensors)
        {
            if (sensor.Status == KinectStatus.Connected)
            {
                SetSensor(sensor);
             }
        }
    }
    

    Basically you are defining a delegate to handle KinectSensor's status changed. Where SetSensor method could be something like this:

    private void SetSensor(KinectSensor newSensor)
    {
        if (kinectSensor != null)
        {
            kinectSensor.Stop();
        }
    
        kinectSensor = newSensor;
    
        if (kinectSensor != null)
        {
            kinectSensor.SkeletonStream.Enable();
            kinectSensor.SkeletonFrameReady += OnSkeletonFrameReady;
            kinectSensor.Start();
         }
    }
    

    Now, OnSkeletonFrameReady it's the "update function". It will be called continuosly at each Kinect sensor update. From inside it you can retrieve information about the joints and render what you want.

    private void OnSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
    {
    
        skelFrame = e.OpenSkeletonFrame();
        skeletons = new Skeleton[kinectSensor.SkeletonStream.FrameSkeletonArrayLength];          
    
        if (skelFrame != null)
        {
            skelFrame.CopySkeletonDataTo(skeletons);
            foreach (Skeleton skel in skeletons) {
            if (skel.TrackingState >= SkeletonTrackingState.Tracked)
            {
                //here's get the joints for each tracked skeleton
                SkeletonPoint rightHand = skel.Joints[JointType.HandRight].Position;
                ....    
             }
        }
    }
    

    Since your are using C# and Kinect, the simple library you could use for rendering you ellipse is XNA.

提交回复
热议问题