Why Kinect Hand Joint is not tracked with Kinect SDK 1.8

I have been working on this for quite some time, and I cannot find why (in most cases) HandJoint is not being tracked. The code is adapted to avoid the situation when this happens (why all zeros and zero values ​​are). I used C # with Kinect SDK v1.8.

I have never written here before, so every comment is rated.

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using Microsoft.Kinect;
 using System.Windows;

 namespace Arcade_Kinect.Kinect
 {
    class KinectAddons
    {
    public KinectSensor kinect;
    public Point? punto;
    public JointType hand;

    public KinectAddons(bool leftHanded, KinectSensor sensor)
    {
        this.kinect = sensor;
        if (kinect != null)
        {
            kinect.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(kinect_SkeletonFrameReady);
            kinect.Start();
            try
            {
                kinect.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
                kinect.SkeletonStream.Enable();
                try
                {
                    kinect.DepthStream.Range = DepthRange.Near;
                    kinect.SkeletonStream.EnableTrackingInNearRange = true;
                }
                catch (InvalidOperationException)
                {

                    kinect.DepthStream.Range = DepthRange.Default;
                    kinect.SkeletonStream.EnableTrackingInNearRange = false;
                }
            }
            catch (InvalidOperationException) { }
        }
        if (leftHanded)
            this.hand = JointType.HandLeft;
        else
            this.hand = JointType.HandRight;

    }

    void kinect_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
    {
        Skeleton[] skeleton = new Skeleton[0];

        using (SkeletonFrame sf = e.OpenSkeletonFrame())
        {
            if (sf != null)
            {
                skeleton = new Skeleton[sf.SkeletonArrayLength];
                sf.CopySkeletonDataTo(skeleton);
                punto = returnPosFromHand(skeleton[0]);
            }
        }
    }

    //saves x and y of the hand
    public Point? returnPosFromHand(Skeleton sk)
    {
        DepthImagePoint depthPoint = new DepthImagePoint();
        bool notWorking = true;
        try
        {
            if (sk.Joints[this.hand].TrackingState == JointTrackingState.Tracked)
            {
                notWorking = false;
                depthPoint = this.kinect.CoordinateMapper.MapSkeletonPointToDepthPoint(sk.Joints[this.hand].Position, DepthImageFormat.Resolution640x480Fps30);
            }
        }
        catch (IndexOutOfRangeException)
        {
            System.Console.WriteLine("Hand capture was lost" + this.hand.ToString());
        }
        catch (Exception e)
        {
            MessageBox.Show(e.Message);
        }
        if (notWorking)
            return null;
        return new Point(depthPoint.X, depthPoint.Y);
    }

        //returns last know value
        public double? readNext()
        {
            if (this.punto.HasValue)
                return punto.Value.X;
            return null;
        }
    }
}
+4
source share
1 answer

Problem

Your problems getting your skeletons from SkeletonFrame

SkeletonFrame.OpenSkeletonFrame()always returns an array with X objects. The tracked person is not necessarily the first skeleton in the array.

. (returnPosFromHand(skeleton[0]);)

, , . Z-index , , . .

+2

Source: https://habr.com/ru/post/1544193/


All Articles