简体   繁体   English

为什么使用Kinect SDK 1.8无法跟踪Kinect手部关节

[英]Why Kinect Hand Joint Not Being Tracked Using Kinect SDK 1.8

I've been working on this for quite a while now, and I cannot find why (most times) the HandJoint isn't tracked. 我已经在这方面工作了很长一段时间,我找不到为什么(大多数时候)没有跟踪HandJoint。 The code is adapted to avoid the situation when this happens (that's why all the nulls and nullables are there). 代码适用于避免发生这种情况时(这就是为什么所有的空值和空值都在那里)。 I used C# with Kinect SDK v1.8. 我使用C#和Kinect SDK v1.8。

I've never posted here before, so EVERY comment is apreciated. 我以前从未在这里发布过,所以每条评论都是相关的。

 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;
        }
    }
}

Problem 问题

Your problems is with getting your skeletons from the SkeletonFrame 你的问题是从SkeletonFrame中获取你的骨架

SkeletonFrame.OpenSkeletonFrame() always return a array with X-objects. SkeletonFrame.OpenSkeletonFrame()始终返回带有X对象的数组。 The person tracked isn't necessarily the first Skeleton in the array. 跟踪的人不一定是阵列中的第一个Skeleton。

That why you get your hand tracking sometimes. 这就是为什么你有时会得到你的手跟踪。 The sometimes is when the tracked skeleton is the first in list ( returnPosFromHand(skeleton[0]); ) 有时是跟踪骨架是列表中的第一个( returnPosFromHand(skeleton[0]);

Solution

Iterate over the skeleton array and check which skeleton is tracked and use that one. 迭代骨架数组并检查跟踪哪个骨架并使用该骨架。 You can order by Z-index and maybe pick the closest one with the sensor. 您可以按Z-index订购,也可以选择与传感器最接近的一个。 Then pass that skeleton to your function. 然后将该骨架传递给您的函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM