Ref: Kinect for Windows SDK 1.8
1. Try to get skeleton raw data in a few statements.
2. Procedure
2-1 Add reference
2-2 using namespace
2-3 add data into a Access data table
3. Coding
// 1. Add Ref, using
using Microsoft.Kinect;
using System.Data.OleDb;
namespace WPFSkeletonRaw
{
/// <summary>
/// MainWindow.xaml 的互動邏輯
/// </summary>
public partial class MainWindow : Window
{
// 2.
KinectSensor sensor;
OleDbConnection conn = new OleDbConnection();
public MainWindow()
{
InitializeComponent();
// 3.
sensor = KinectSensor.KinectSensors[0];
sensor.SkeletonStream.Enable();
sensor.SkeletonFrameReady += sensor_SkeletonFrameReady;
sensor.Start();
sensor.ElevationAngle = 10;
conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Database1.accdb";
conn.Open();
for (int i = 0; i < 20; i++)
for (int j = 0; j < 3; j++)
{
TranslateTransform TR = new TranslateTransform(j * 100, i * 30);
txtbx[i, j] = new TextBox();
txtbx[i, j].Width = 90;
txtbx[i, j].Height = 25;
txtbx[i, j].RenderTransform = TR;
Can1.Children.Add(txtbx[i, j]);
}
}
TextBox[,] txtbx = new TextBox[20, 3];
void sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
Skeleton[] skeletons = new Skeleton[0];
using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
{
if (skeletonFrame != null)
{
skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
skeletonFrame.CopySkeletonDataTo(skeletons);
}
}
foreach (Skeleton skeleton in skeletons)
{
if (skeleton.TrackingState == SkeletonTrackingState.Tracked)
{
//DrawTrackedSkeletonJoints(skeleton.Joints);
for (int i=0; i<20; i++)
{
string x, y, z;
x = skeleton.Joints[(JointType)i].Position.X.ToString();
y = skeleton.Joints[(JointType)i].Position.Y.ToString();
z = skeleton.Joints[(JointType)i].Position.Z.ToString();
txtbx[i, 0].Text = x;
txtbx[i, 1].Text = y;
txtbx[i, 2].Text = z;
OleDbCommand cmmd = new OleDbCommand("INSERT INTO JointTrace (JointNumber, X,Y,Z) Values("
+ i.ToString() + ", " + x.ToString() + ", " + y.ToString() + ", " + z.ToString() + ")", conn);
cmmd.ExecuteNonQuery();
}
}
else if (skeleton.TrackingState == SkeletonTrackingState.PositionOnly)
{
//txtbk.Text += skeleton.Joints[0].Position.ToString() + "\r\n";
}
}
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
sensor.SkeletonStream.Disable();
sensor.Stop();
conn.Close();
}
}
4. Example
Example