Kinect v1骨架流关节位置XYZ

时间:2019-01-21 08:16:02

标签: c# console position kinect kinect-sdk

我正在使用Kinect骨架流提取右侧位置。

我要沿圆形路径移动手,并希望提取手的所有X Y Z位置并将其保存在csv文件中。现在,我的代码仅显示一次位置。

我要提取位置,直到我的手在kinect的前面运动,并且当我将手移到kinect之前,传感器应该停止跟踪。 当将手从传感器前面移开时,我不知道该如何实施,然后应该停下来。我也必须通过串行端口发送所有位置值。

这是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Microsoft.Kinect;
using Microsoft.Kinect.Toolkit;
using System.IO;

namespace SkeletonPosition
{

class Gesture
{

    static int _currentGesture = 0;
    static int _frameCount = 0;
    static bool startPose = false;


    public string[] Update(Skeleton skeleton)
    {

        {
            float rhX = skeleton.Joints[JointType.HandRight].Position.X;
            float rhY = skeleton.Joints[JointType.HandRight].Position.Y;
            float rhZ = skeleton.Joints[JointType.HandRight].Position.Z;

            float erX = skeleton.Joints[JointType.ElbowRight].Position.X;
            float erY = skeleton.Joints[JointType.ElbowRight].Position.Y;
            float erZ = skeleton.Joints[JointType.ElbowRight].Position.Z;

            float srX = skeleton.Joints[JointType.ShoulderRight].Position.X;
            float srY = skeleton.Joints[JointType.ShoulderRight].Position.Y;
            float srZ = skeleton.Joints[JointType.ShoulderRight].Position.Z;

           string[] values = { rhX.ToString(), rhY.ToString(), rhZ.ToString() };

            if (!startPose)
            {
                    if(skeleton.Joints[JointType.HandRight].Position.Y > skeleton.Joints[JointType.ElbowRight].Position.Y)
                    _frameCount++;

                        if (_frameCount == 30)

                                {

                               Console.WriteLine("Positions are ready");

                               Console.Write("Right hand X-Position =  ");
                               Console.WriteLine(rhX);
                               Console.Write("Right hand Y-Position =  ");
                               Console.WriteLine(rhY);
                               Console.Write("Right hand Y-Position =  ");
                               Console.WriteLine(rhY);                      
                               Console.Write("Right hand Z-Position = ");
                               Console.WriteLine(rhZ);


                                var file = @"C:\myOutput.csv";

                                using (var stream = File.CreateText(file))
                                        {

                                         string first = rhX.ToString();
                                         string second = rhY.ToString();
                                         string third = rhZ.ToString();
                                         string csvRow = string.Format("{0},{1},{2}", first, second, third);

                                         stream.WriteLine(csvRow);

                                        }


                        }

            }


        }

        return values;
        _frameCount++;
      startPose = false;
    }
}

}

0 个答案:

没有答案