简体   繁体   English

Kinect关节位置X,Y,Z始终= 0

[英]Kinect joint positions X,Y,Z always = 0

I am trying to catch joint X, Y, Z positions and write them into txt file on button click. 我试图抓住关节X,Y,Z位置并在按钮点击时将它们写入txt文件。 Everything is fine, but every time, I get 0, 0, 0 for X,Y,Z. 一切都很好,但每次,我得到0,0,0为X,Y,Z。 What could be wrong? 可能有什么不对? My app is also displaying / drawing the skeleton, so I guess that it should have the positions of each joint. 我的应用程序也显示/绘制骨架,所以我猜它应该有每个关节的位置。 I even tried to print X position of head joint to the textbox in the drawing method, but with same result (X=0). 我甚至尝试在绘图方法中将头部关节的X位置打印到文本框,但结果相同(X = 0)。

using System;
using System.Collections.Generic;
using System.Linq; 
using System.Windows; 
using System.Windows.Media; 
using Microsoft.Kinect; 
using System.IO;

namespace WpfApplication1
{
    public partial class MainWindow : Window
    {


  private double rightX;
  private double rightY;
  private double rightZ;

  public void positions(Skeleton skeleton)
  {
  // get the joint
  Joint rightHand = skeleton.Joints[JointType.HandRight];

  // get the individual points of the right hand
  rightX = rightHand.Position.X;
  rightY = rightHand.Position.Y;
  rightZ = rightHand.Position.Z;     
  }



 void sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
    {
        //declare an array of Skeletons
        Skeleton[] skeletons = new Skeleton[1];

        //Opens a SkeletonFrame object, which contains one frame of skeleton data.
        using (SkeletonFrame skeletonframe = e.OpenSkeletonFrame())
        {
            //Check if the Frame is Indeed open 
            if (skeletonframe != null)
            {

                skeletons = new Skeleton[skeletonframe.SkeletonArrayLength];

                // Copies skeleton data to an array of Skeletons, where each Skeleton contains a collection of the joints.
                skeletonframe.CopySkeletonDataTo(skeletons);

                //draw the Skeleton based on the Default Mode(Standing), "Seated"
                if (sensor.SkeletonStream.TrackingMode == SkeletonTrackingMode.Default)
                {
                    //Draw standing Skeleton
                    DrawStandingSkeletons(skeletons);
                }
                else if (sensor.SkeletonStream.TrackingMode == SkeletonTrackingMode.Seated)
                {
                    //Draw a Seated Skeleton with 10 joints
                    DrawSeatedSkeletons(skeletons);
                }
            }

        }

    }



  private void stoji_Click(object sender, RoutedEventArgs e)
  {
  File.AppendAllText(@"E:\skuska.txt", rightX + ", " + rightY + ", " +rightZ + Environment.NewLine);
   }
  }

You have to start the sensor, subscribe to the SkeletonFrameReady event and update the positions in the eventhandler. 您必须启动传感器,订阅SkeletonFrameReady事件并更新事件处理程序中的位置。 Starting to Develop with Kinect might be useful for you. 使用Kinect开始开发可能对您有用。

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

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