Skip to content

Instantly share code, notes, and snippets.

Created July 11, 2012 22:14
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3094082 to your computer and use it in GitHub Desktop.
Save anonymous/3094082 to your computer and use it in GitHub Desktop.
Updated 1.5 code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Kinect;
using Microsoft.Samples.Kinect.WpfViewers;
using Coding4Fun.Kinect.Wpf;
using System.Runtime;
using System.Threading;
using System.Speech.Recognition;
using System.Speech.AudioFormat;
using SpeechRecognizer;
using FlyingText;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
#region Variables
bool closing = false;
int totalFrames1 = 0;
int timecounter = 10;
KinectSensor sensor;
const int skeletonCount = 6;
Skeleton[] allSkeletons = new Skeleton[skeletonCount];
DateTime lastTime = DateTime.MaxValue;
double[, ,] skeleton_frames = new double[2000, 21, 3];
double[, ,] skeleton_frames_doctor = new double[2000, 21, 3];
double[, ,] skeleton_frames_doctor_new = new double[2000, 21, 3];
int[, ,] Time_frames_doctor = new int[2000, 1, 3];
int[, ,] Time_frames = new int[2000, 1, 3];
int[, ,] Trans_Vec = new int[1, 1, 3];
string[] delim = new string[3];
const int RED_IDX = 2;
const int GREEN_IDX = 1;
const int BLUE_IDX = 0;
byte[] depthFrame32 = new byte[320 * 240 * 4];
int count = 0;
int total_frames = 0;
DepthImageFrame depthFrame;
int[,] JointNo = new int[19, 2];
bool pause = false;
bool resume = false;
bool start = false;
bool stop = false;
SpeechRecognizer.SpeechRecognizer sr;
private SkeletonDetected sd = new SkeletonDetected();
#endregion
Dictionary<JointType, Brush> jointColors = new Dictionary<JointType, Brush>()
{
{JointType.HipCenter, new SolidColorBrush(Color.FromRgb(169, 176, 155))},
{JointType.Spine, new SolidColorBrush(Color.FromRgb(169, 176, 155))},
{JointType.ShoulderCenter, new SolidColorBrush(Color.FromRgb(168, 230, 29))},
{JointType.Head, new SolidColorBrush(Color.FromRgb(200, 0, 0))},
{JointType.ShoulderLeft, new SolidColorBrush(Color.FromRgb(79, 84, 33))},
{JointType.ElbowLeft, new SolidColorBrush(Color.FromRgb(84, 33, 42))},
{JointType.WristLeft, new SolidColorBrush(Color.FromRgb(255, 126, 0))},
{JointType.HandLeft, new SolidColorBrush(Color.FromRgb(215, 86, 0))},
{JointType.ShoulderRight, new SolidColorBrush(Color.FromRgb(33, 79, 84))},
{JointType.ElbowRight, new SolidColorBrush(Color.FromRgb(33, 33, 84))},
{JointType.WristRight, new SolidColorBrush(Color.FromRgb(77, 109, 243))},
{JointType.HandRight, new SolidColorBrush(Color.FromRgb(37, 69, 243))},
{JointType.HipLeft, new SolidColorBrush(Color.FromRgb(77, 109, 243))},
{JointType.KneeLeft, new SolidColorBrush(Color.FromRgb(69, 33, 84))},
{JointType.AnkleLeft, new SolidColorBrush(Color.FromRgb(229, 170, 122))},
{JointType.FootLeft, new SolidColorBrush(Color.FromRgb(255, 126, 0))},
{JointType.HipRight, new SolidColorBrush(Color.FromRgb(181, 165, 213))},
{JointType.KneeRight, new SolidColorBrush(Color.FromRgb(71, 222, 76))},
{JointType.AnkleRight, new SolidColorBrush(Color.FromRgb(245, 228, 156))},
{JointType.FootRight, new SolidColorBrush(Color.FromRgb(77, 109, 243))}
};
private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.sr.SetLabel += (x) => { this.speechLabel.Content = x; };
this.sd.SetLabel += (x) => { this.skeletonDetected.Content = x; };
sensor = kinectSensorChooser1.Kinect;
JointNo[0, 0] = 1;
JointNo[0, 1] = 2;
JointNo[1, 0] = 2;
JointNo[1, 1] = 3;
JointNo[2, 0] = 3;
JointNo[2, 1] = 4;
JointNo[3, 0] = 3;
JointNo[3, 1] = 9;
JointNo[4, 0] = 9;
JointNo[4, 1] = 10;
JointNo[5, 0] = 10;
JointNo[5, 1] = 11;
JointNo[6, 0] = 11;
JointNo[6, 1] = 12;
JointNo[7, 0] = 3;
JointNo[7, 1] = 5;
JointNo[8, 0] = 5;
JointNo[8, 1] = 6;
JointNo[9, 0] = 6;
JointNo[9, 1] = 7;
JointNo[10, 0] = 7;
JointNo[10, 1] = 8;
JointNo[11, 0] = 1;
JointNo[11, 1] = 13;
JointNo[12, 0] = 13;
JointNo[12, 1] = 14;
JointNo[13, 0] = 14;
JointNo[13, 1] = 15;
JointNo[14, 0] = 15;
JointNo[14, 1] = 16;
JointNo[15, 0] = 1;
JointNo[15, 1] = 17;
JointNo[16, 0] = 17;
JointNo[16, 1] = 18;
JointNo[17, 0] = 18;
JointNo[17, 1] = 19;
JointNo[18, 0] = 19;
JointNo[18, 1] = 20;
char[] delimiters = new char[] { '|', ' ' };
string file_name_2 = "C:\\Kinect_for_Physiotherapy\\doctor.txt";
string[] lines = System.IO.File.ReadAllLines(@file_name_2);
foreach (string line in lines)
{
string[] seperated = line.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
seperated.CopyTo(delim, 0);
skeleton_frames_doctor[total_frames, count, 0] = int.Parse(delim[0]);
skeleton_frames_doctor[total_frames, count, 1] = int.Parse(delim[1]);
skeleton_frames_doctor[total_frames, count, 2] = int.Parse(delim[2]);
count++;
if (count == 21)
{
count = 0;
total_frames++;
}
}
lastTime = DateTime.Now;
kinectSensorChooser1.KinectSensorChanged += new DependencyPropertyChangedEventHandler(
kinectSensorChooser1_KinectSensorChanged);
this.sr = SpeechRecognizer.SpeechRecognizer.Create();
this.sr.SaidSomething += this.RecognizeSaidSomething;
this.sr.Start(sensor.AudioSource);
}
private void kinectSensorChooser1_Loaded(object sender, RoutedEventArgs e)
{
kinectSensorChooser1.Kinect.SkeletonStream.Enable();
}
private void StopKinect(KinectSensor sensor)
{
if (sensor != null)
{
if (sensor.IsRunning)
{
//stop sensor
sensor.Stop();
//stop audio if not null
if (sensor.AudioSource != null)
{
sensor.AudioSource.Stop();
}
}
}
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
closing = true;
StopKinect(kinectSensorChooser1.Kinect);
}
void kinectSensorChooser1_KinectSensorChanged(object sender, DependencyPropertyChangedEventArgs e)
{
KinectSensor old = (KinectSensor)e.OldValue;
StopKinect(old);
KinectSensor sensor = (KinectSensor)e.NewValue;
if (sensor == null)
{
return;
}
sensor.AllFramesReady += new EventHandler<AllFramesReadyEventArgs>(sensor_AllFramesReady);
sensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
sensor.AudioSource.Start();
sensor.SkeletonStream.Enable();
try
{
sensor.Start();
}
catch (System.IO.IOException)
{
kinectSensorChooser1.AppConflictOccurred();
}
}
private void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
{
depthFrame = e.OpenDepthImageFrame();
}
Polyline getBodySegment(Microsoft.Kinect.JointCollection joints, Brush brush, params JointType[] ids)
{
PointCollection points = new PointCollection(ids.Length);
for (int i = 0; i < ids.Length; ++i)
{
points.Add(getDisplayPosition(joints[ids[i]]));
}
Polyline polyline = new Polyline();
polyline.Points = points;
polyline.Stroke = brush;
polyline.StrokeThickness = 1;
return polyline;
}
Polyline getDoctorBody(Brush brush, int frame, int id1, int id2, int id3, int id4, int id5)
{
PointCollection points = new PointCollection(20);
points.Add(new Point(skeleton_frames_doctor_new[frame, id1 - 1, 0], skeleton_frames_doctor[frame, id1 - 1, 1]));
points.Add(new Point(skeleton_frames_doctor_new[frame, id2 - 1, 0], skeleton_frames_doctor[frame, id2 - 1, 1]));
points.Add(new Point(skeleton_frames_doctor_new[frame, id3 - 1, 0], skeleton_frames_doctor[frame, id3 - 1, 1]));
points.Add(new Point(skeleton_frames_doctor_new[frame, id4 - 1, 0], skeleton_frames_doctor[frame, id4 - 1, 1]));
points.Add(new Point(skeleton_frames_doctor_new[frame, id5 - 1, 0], skeleton_frames_doctor[frame, id5 - 1, 1]));
Polyline polyline = new Polyline();
polyline.Points = points;
polyline.Stroke = brush;
polyline.StrokeThickness = 1;
return polyline;
}
private Point getDisplayPosition(Joint joint)
{
float depthX, depthY;
KinectSensor sensor = kinectSensorChooser1.Kinect;
DepthImageFormat depthImageFormat = sensor.DepthStream.Format;
DepthImagePoint depthPoint = sensor.MapSkeletonPointToDepth(joint.Position, depthImageFormat);
depthX = depthPoint.X;
depthY = depthPoint.Y;
depthX = Math.Max(0, Math.Min(depthX * 320, 320));
depthY = Math.Max(0, Math.Min(depthY * 240, 240));
int colorX, colorY;
ColorImagePoint colorPoint = depthFrame.MapToColorImagePoint(depthPoint.X, depthPoint.Y,
sensor.ColorStream.Format);
colorX = colorPoint.X;
colorY = colorPoint.Y;
return new Point((int)(skeleton.Width * colorX / 640.0), (int)(skeleton.Height * colorY / 480));
}
void nui_SkeletonFrameReady(object sender, AllFramesReadyEventArgs e)
{
if (timecounter > 0)
{
Thread.Sleep(1000);
frameRate.Content = timecounter.ToString() + " fps";
timecounter--;
}
int iSkeleton = 0;
int joint_count = 0;
double XPos;
double YPos;
++totalFrames1;
DateTime startTime = DateTime.Now;
string bb1 = Convert.ToString(totalFrames1);
//string file_name_2 = "C:\\Research\\Kinect\\Junk3\\coord" + bb1 + ".txt";
//System.IO.StreamWriter file_dist = new System.IO.StreamWriter(@file_name_2);
Brush[] brushes = new Brush[6];
brushes[0] = new SolidColorBrush(Color.FromRgb(255, 0, 0));
brushes[1] = new SolidColorBrush(Color.FromRgb(0, 255, 0));
brushes[2] = new SolidColorBrush(Color.FromRgb(64, 255, 255));
brushes[3] = new SolidColorBrush(Color.FromRgb(255, 255, 64));
brushes[4] = new SolidColorBrush(Color.FromRgb(255, 64, 255));
brushes[5] = new SolidColorBrush(Color.FromRgb(128, 128, 255));
Brush[] doctorBrushes = new Brush[6];
doctorBrushes[0] = new SolidColorBrush(Colors.LimeGreen);
doctorBrushes[1] = new SolidColorBrush(Colors.LimeGreen);
doctorBrushes[2] = new SolidColorBrush(Colors.LimeGreen);
doctorBrushes[3] = new SolidColorBrush(Colors.LimeGreen);
doctorBrushes[4] = new SolidColorBrush(Colors.LimeGreen);
doctorBrushes[5] = new SolidColorBrush(Colors.LimeGreen);
skeleton.Children.Clear();
//byte[] skeletonFrame32 = new byte[(int)(skeleton.Width) * (int)(skeleton.Height) * 4];
//file_dist.WriteLine("{0},{1}", startTime.Second, startTime.Millisecond);
joint_count = 0;
Time_frames[totalFrames1, 0, 0] = startTime.Millisecond;
Time_frames[totalFrames1, 0, 1] = startTime.Second;
Time_frames[totalFrames1, 0, 2] = startTime.Minute;
Skeleton skeletons = new Skeleton();
skeletons = (from s in allSkeletons
where s.TrackingState == SkeletonTrackingState.Tracked ||
s.TrackingState == SkeletonTrackingState.PositionOnly
select s).FirstOrDefault();
if (skeletons == null)
{
return;
}
if ((skeletons.TrackingState == SkeletonTrackingState.Tracked ||
skeletons.TrackingState == SkeletonTrackingState.PositionOnly))
{
// Draw joints
joint_count = 0;
foreach (Joint joint in skeletons.Joints)
{
Point jointPos = getDisplayPosition(joint);
//storing the patients x y coordinates
skeleton_frames[totalFrames1, joint_count, 0] = (double)jointPos.X;
skeleton_frames[totalFrames1, joint_count, 1] = (double)jointPos.Y;
//getting the doctors x y coordinates
XPos = (skeleton_frames[totalFrames1, 0, 0]) - (skeleton_frames_doctor[totalFrames1, 0, 0]);
YPos = (skeleton_frames[totalFrames1, 0, 1]) - (skeleton_frames_doctor[totalFrames1, 0, 1]);
//Scaling and transformation of doctors frame to patients frame
skeleton_frames_doctor_new[totalFrames1, joint_count, 0] = skeleton_frames_doctor[totalFrames1,
joint_count, 0] + XPos;
skeleton_frames_doctor_new[totalFrames1, joint_count, 1] = skeleton_frames_doctor[totalFrames1,
joint_count, 1] + YPos;
for (int j = 0; j < 19; j++)
{
double DistP = Math.Sqrt(Math.Pow((skeleton_frames[totalFrames1, JointNo[j, 0] - 1, 0]) -
skeleton_frames[totalFrames1, JointNo[j, 1] - 1, 0], 2) +
Math.Pow((skeleton_frames[totalFrames1, JointNo[j, 0] - 1, 1]) -
skeleton_frames[totalFrames1, JointNo[j, 1] - 1, 1], 2));
double DistD = Math.Sqrt(Math.Pow((skeleton_frames_doctor_new[totalFrames1, JointNo[j, 0] - 1, 0]) -
skeleton_frames_doctor_new[totalFrames1, JointNo[j, 1] - 1, 0], 2) +
Math.Pow((skeleton_frames_doctor_new[totalFrames1, JointNo[j, 0] - 1, 1]) -
skeleton_frames_doctor_new[totalFrames1, JointNo[j, 1] - 1, 1], 2));
double alpha = DistP / DistD;
skeleton_frames_doctor_new[totalFrames1, JointNo[j, 1] - 1, 0] =
skeleton_frames_doctor_new[totalFrames1, JointNo[j, 0] - 1, 0] +
(skeleton_frames_doctor_new[totalFrames1, JointNo[j, 1] - 1, 0] -
skeleton_frames_doctor_new[totalFrames1, JointNo[j, 0] - 1, 0]) * (alpha);
skeleton_frames_doctor_new[totalFrames1, JointNo[j, 1] - 1, 1] =
skeleton_frames_doctor_new[totalFrames1, JointNo[j, 0] - 1, 1] +
(skeleton_frames_doctor_new[totalFrames1, JointNo[j, 1] - 1, 1] -
skeleton_frames_doctor_new[totalFrames1, JointNo[j, 0] - 1, 1]) * (alpha);
}
joint_count++;
}
bool ispaused = false;
Brush brush = brushes[iSkeleton % brushes.Length];
Brush doctorBrush = doctorBrushes[iSkeleton % doctorBrushes.Length];
skeleton.Children.Add(getBodySegment(skeletons.Joints, brush, JointType.HipCenter, JointType.Spine,
JointType.ShoulderCenter, JointType.Head));
skeleton.Children.Add(getBodySegment(skeletons.Joints, brush, JointType.ShoulderCenter,
JointType.ShoulderLeft, JointType.ElbowLeft, JointType.WristLeft, JointType.HandLeft));
skeleton.Children.Add(getBodySegment(skeletons.Joints, brush, JointType.ShoulderCenter,
JointType.ShoulderRight, JointType.ElbowRight, JointType.WristRight, JointType.HandRight));
skeleton.Children.Add(getBodySegment(skeletons.Joints, brush, JointType.HipCenter,
JointType.HipLeft, JointType.KneeLeft, JointType.AnkleLeft, JointType.FootLeft));
skeleton.Children.Add(getBodySegment(skeletons.Joints, brush, JointType.HipCenter,
JointType.HipRight, JointType.KneeRight, JointType.AnkleRight, JointType.FootRight));
skeleton.Children.Add(getDoctorBody(doctorBrush, totalFrames1 - 1, 1, 2, 3, 4, 4));
skeleton.Children.Add(getDoctorBody(doctorBrush, totalFrames1 - 1, 3, 5, 6, 7, 8));
skeleton.Children.Add(getDoctorBody(doctorBrush, totalFrames1 - 1, 3, 9, 10, 11, 12));
skeleton.Children.Add(getDoctorBody(doctorBrush, totalFrames1 - 1, 1, 13, 14, 15, 16));
skeleton.Children.Add(getDoctorBody(doctorBrush, totalFrames1 - 1, 1, 17, 18, 19, 20));
if (stop == true)
{
skeleton.Children.Clear();
}
else if (pause == true)
{
skeleton.Effect.Freeze();
ispaused = true;
}
else if (ispaused == true & resume == true)
{
skeleton.Children.Add(getBodySegment(skeletons.Joints, brush, JointType.HipCenter, JointType.Spine,
JointType.ShoulderCenter, JointType.Head));
skeleton.Children.Add(getBodySegment(skeletons.Joints, brush, JointType.ShoulderCenter,
JointType.ShoulderLeft, JointType.ElbowLeft, JointType.WristLeft, JointType.HandLeft));
skeleton.Children.Add(getBodySegment(skeletons.Joints, brush, JointType.ShoulderCenter,
JointType.ShoulderRight, JointType.ElbowRight, JointType.WristRight, JointType.HandRight));
skeleton.Children.Add(getBodySegment(skeletons.Joints, brush, JointType.HipCenter,
JointType.HipLeft, JointType.KneeLeft, JointType.AnkleLeft, JointType.FootLeft));
skeleton.Children.Add(getBodySegment(skeletons.Joints, brush, JointType.HipCenter,
JointType.HipRight, JointType.KneeRight, JointType.AnkleRight, JointType.FootRight));
skeleton.Children.Add(getDoctorBody(doctorBrush, totalFrames1 - 1, 1, 2, 3, 4, 4));
skeleton.Children.Add(getDoctorBody(doctorBrush, totalFrames1 - 1, 3, 5, 6, 7, 8));
skeleton.Children.Add(getDoctorBody(doctorBrush, totalFrames1 - 1, 3, 9, 10, 11, 12));
skeleton.Children.Add(getDoctorBody(doctorBrush, totalFrames1 - 1, 1, 13, 14, 15, 16));
skeleton.Children.Add(getDoctorBody(doctorBrush, totalFrames1 - 1, 1, 17, 18, 19, 20));
}
}
else if (start == true)
{
bool ispaused = false;
Brush brush = brushes[iSkeleton % brushes.Length];
Brush doctorBrush = doctorBrushes[iSkeleton % doctorBrushes.Length];
// Draw joints
joint_count = 0;
foreach (Joint joint in skeletons.Joints)
{
Point jointPos = getDisplayPosition(joint);
//storing the patients x y coordinates
skeleton_frames[totalFrames1, joint_count, 0] = (double)jointPos.X;
skeleton_frames[totalFrames1, joint_count, 1] = (double)jointPos.Y;
//getting the doctors x y coordinates
XPos = (skeleton_frames[totalFrames1, 0, 0]) - (skeleton_frames_doctor[totalFrames1, 0, 0]);
YPos = (skeleton_frames[totalFrames1, 0, 1]) - (skeleton_frames_doctor[totalFrames1, 0, 1]);
//Scaling and transformation of doctors frame to patients frame
skeleton_frames_doctor_new[totalFrames1, joint_count, 0] =
skeleton_frames_doctor[totalFrames1, joint_count, 0] + XPos;
skeleton_frames_doctor_new[totalFrames1, joint_count, 1] =
skeleton_frames_doctor[totalFrames1, joint_count, 1] + YPos;
for (int j = 0; j < 19; j++)
{
double DistP = Math.Sqrt(Math.Pow((skeleton_frames[totalFrames1, JointNo[j, 0] - 1, 0]) -
skeleton_frames[totalFrames1, JointNo[j, 1] - 1, 0], 2) +
Math.Pow((skeleton_frames[totalFrames1, JointNo[j, 0] - 1, 1]) -
skeleton_frames[totalFrames1, JointNo[j, 1] - 1, 1], 2));
double DistD = Math.Sqrt(Math.Pow((skeleton_frames_doctor_new[totalFrames1, JointNo[j, 0] - 1, 0]) -
skeleton_frames_doctor_new[totalFrames1, JointNo[j, 1] - 1, 0], 2) +
Math.Pow((skeleton_frames_doctor_new[totalFrames1, JointNo[j, 0] - 1, 1]) -
skeleton_frames_doctor_new[totalFrames1, JointNo[j, 1] - 1, 1], 2));
double alpha = DistP / DistD;
skeleton_frames_doctor_new[totalFrames1, JointNo[j, 1] - 1, 0] =
skeleton_frames_doctor_new[totalFrames1, JointNo[j, 0] - 1, 0] +
(skeleton_frames_doctor_new[totalFrames1, JointNo[j, 1] - 1, 0] -
skeleton_frames_doctor_new[totalFrames1, JointNo[j, 0] - 1, 0]) * (alpha);
skeleton_frames_doctor_new[totalFrames1, JointNo[j, 1] - 1, 1] =
skeleton_frames_doctor_new[totalFrames1, JointNo[j, 0] - 1, 1] +
(skeleton_frames_doctor_new[totalFrames1, JointNo[j, 1] - 1, 1] -
skeleton_frames_doctor_new[totalFrames1, JointNo[j, 0] - 1, 1]) * (alpha);
}
//Line jointLine = new Line();
//jointLine.X1 = jointPos.X - 3;
//jointLine.X2 = jointLine.X1 + 6;
//jointLine.Y1 = jointLine.Y2 = jointPos.Y;
//jointLine.Stroke = jointColors[joint.ID];
//jointLine.StrokeThickness = 6;
//skeleton.Children.Add(jointLine);
//file_dist.WriteLine("{0}, {1},{2}", jointPos.X.GetType(),jointPos.X, jointPos.Y);
//joint_count++;
joint_count++;
}
skeleton.Children.Add(getBodySegment(skeletons.Joints, brush, JointType.HipCenter, JointType.Spine,
JointType.ShoulderCenter, JointType.Head));
skeleton.Children.Add(getBodySegment(skeletons.Joints, brush, JointType.ShoulderCenter,
JointType.ShoulderLeft, JointType.ElbowLeft, JointType.WristLeft, JointType.HandLeft));
skeleton.Children.Add(getBodySegment(skeletons.Joints, brush, JointType.ShoulderCenter,
JointType.ShoulderRight, JointType.ElbowRight, JointType.WristRight, JointType.HandRight));
skeleton.Children.Add(getBodySegment(skeletons.Joints, brush, JointType.HipCenter
, JointType.HipLeft, JointType.KneeLeft, JointType.AnkleLeft, JointType.FootLeft));
skeleton.Children.Add(getBodySegment(skeletons.Joints, brush, JointType.HipCenter,
JointType.HipRight, JointType.KneeRight, JointType.AnkleRight, JointType.FootRight));
skeleton.Children.Add(getDoctorBody(doctorBrush, totalFrames1 - 1, 1, 2, 3, 4, 4));
skeleton.Children.Add(getDoctorBody(doctorBrush, totalFrames1 - 1, 3, 5, 6, 7, 8));
skeleton.Children.Add(getDoctorBody(doctorBrush, totalFrames1 - 1, 3, 9, 10, 11, 12));
skeleton.Children.Add(getDoctorBody(doctorBrush, totalFrames1 - 1, 1, 13, 14, 15, 16));
skeleton.Children.Add(getDoctorBody(doctorBrush, totalFrames1 - 1, 1, 17, 18, 19, 20));
if (stop == true)
{
skeleton.Children.Clear();
}
else if (pause == true)
{
skeleton.Effect.Freeze();
ispaused = true;
}
else if (ispaused == true & resume == true)
{
skeleton.Children.Add(getBodySegment(skeletons.Joints, brush, JointType.HipCenter,
JointType.Spine, JointType.ShoulderCenter, JointType.Head));
skeleton.Children.Add(getBodySegment(skeletons.Joints, brush, JointType.ShoulderCenter,
JointType.ShoulderLeft, JointType.ElbowLeft, JointType.WristLeft, JointType.HandLeft));
skeleton.Children.Add(getBodySegment(skeletons.Joints, brush, JointType.ShoulderCenter,
JointType.ShoulderRight, JointType.ElbowRight, JointType.WristRight, JointType.HandRight));
skeleton.Children.Add(getBodySegment(skeletons.Joints, brush, JointType.HipCenter,
JointType.HipLeft, JointType.KneeLeft, JointType.AnkleLeft, JointType.FootLeft));
skeleton.Children.Add(getBodySegment(skeletons.Joints, brush, JointType.HipCenter,
JointType.HipRight, JointType.KneeRight, JointType.AnkleRight, JointType.FootRight));
skeleton.Children.Add(getDoctorBody(doctorBrush, totalFrames1 - 1, 1, 2, 3, 4, 4));
skeleton.Children.Add(getDoctorBody(doctorBrush, totalFrames1 - 1, 3, 5, 6, 7, 8));
skeleton.Children.Add(getDoctorBody(doctorBrush, totalFrames1 - 1, 3, 9, 10, 11, 12));
skeleton.Children.Add(getDoctorBody(doctorBrush, totalFrames1 - 1, 1, 13, 14, 15, 16));
skeleton.Children.Add(getDoctorBody(doctorBrush, totalFrames1 - 1, 1, 17, 18, 19, 20));
}
}
iSkeleton++;
}
private void Window_Closing_1(object sender, System.ComponentModel.CancelEventArgs e)
{
}
private void Window_Closed(object sender, EventArgs e)
{
string file_name_2 = "C:\\Kinect_for_Physiotherapy\\patient.txt";
System.IO.StreamWriter file_dist = new System.IO.StreamWriter(@file_name_2);
for (int i = 0; i < totalFrames1; i++)
{
for (int j = 0; j < 20; j++)
{
file_dist.WriteLine("{0} {1} {2}", skeleton_frames[i, j, 0], skeleton_frames[i, j, 1],
skeleton_frames[i, j, 2]);
}
file_dist.WriteLine("{0} {1} {2}", Time_frames[i, 0, 2] * 60000 + Time_frames[i, 0, 1] *
1000 + Time_frames[i, 0, 0], 0, 0);
}
file_dist.Close();
sensor.Stop();
Environment.Exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment