我试图通过Windows窗体应用程序将Kinect传感器的关节输入存储到文本文件中。香港专业教育学院尝试了一些不同的方法,但他们似乎没有工作。任何帮助将不胜感激。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Kinect;
namespace kinect
{
public partial class Form1 : Form
{
KinectSensor KinectSensor = null;
BodyFrameReader bodyFrameReader = null;
Body[] bodies = null;
public Form1()
{
InitialiseKinect();
}
public void InitialiseKinect()
{
KinectSensor = KinectSensor.GetDefault();
if (KinectSensor != null)
{
//turn on kinect
KinectSensor.Open();
}
bodyFrameReader = KinectSensor.BodyFrameSource.OpenReader();
if (bodyFrameReader != null)
{
bodyFrameReader.FrameArrived += Reader_FrameArrived;
}
}
private void Reader_FrameArrived(object sensor, BodyFrameArrivedEventArgs e)
{
bool dataRecieved = false;
using (BodyFrame bodyFrame = e.FrameReference.AcquireFrame())
{
if (bodyFrame != null)
{
if (bodies == null)
{
bodies = new Body[bodyFrame.BodyCount];
}
bodyFrame.GetAndRefreshBodyData(bodies);
dataRecieved = true;
}
if (dataRecieved)
{
foreach (Body body in bodies)
{
if (body.IsTracked)
{
IReadOnlyDictionary<JointType, Joint> joints = body.Joints;
Dictionary<JointType, Point> jointPoints = new Dictionary<JointType, Point>();
//Left points
Joint leftShoulder = joints[JointType.ShoulderLeft];
float ls_distance_x = leftShoulder.Position.X;
float ls_distance_y = leftShoulder.Position.Y;
float ls_distance_z = leftShoulder.Position.Z;
Joint leftElbow = joints[JointType.ElbowLeft];
float le_distance_x = leftElbow.Position.X;
float le_distance_y = leftElbow.Position.Y;
float le_distance_z = leftElbow.Position.Z;
Joint leftwrist = joints[JointType.WristLeft];
float lw_distance_x = leftwrist.Position.X;
float lw_distance_y = leftwrist.Position.Y;
float lw_distance_z = leftwrist.Position.Z;
Joint leftHand = joints[JointType.HandLeft];
float lh_distance_x = leftHand.Position.X;
float lh_distance_y = leftHand.Position.Y;
float lh_distance_z = leftHand.Position.Z;
Joint tipLeftHand = joints[JointType.HandTipLeft];
float lth_distance_x = tipLeftHand.Position.X;
float lth_distance_y = tipLeftHand.Position.Y;
float lth_distance_z = tipLeftHand.Position.Z;
//Right points
Joint rightShoulder = joints[JointType.ShoulderRight];
float rs_distance_x = rightShoulder.Position.X;
float rs_distance_y = rightShoulder.Position.Y;
float rs_distance_z = rightShoulder.Position.Z;
Joint rightElbow = joints[JointType.ElbowRight];
float re_distance_x = rightElbow.Position.X;
float re_distance_y = rightElbow.Position.Y;
float re_distance_z = rightElbow.Position.Z;
Joint rightWrist = joints[JointType.WristRight];
float rw_distance_x = rightWrist.Position.X;
float rw_distance_y = rightWrist.Position.Y;
float rw_distance_z = rightWrist.Position.Z;
Joint rightHand = joints[JointType.HandRight];
float rh_distance_x = rightHand.Position.X;
float rh_distance_y = rightHand.Position.Y;
float rh_distance_z = rightHand.Position.Z;
Joint tipRightHand = joints[JointType.HandTipRight];
float rth_distance_x = tipRightHand.Position.X;
float rth_distance_y = tipRightHand.Position.Y;
float rth_distance_z = tipRightHand.Position.Z;
float rth_distance_n = tipRightHand.Position.N;
}
}
}
}
}
}
}