private void KinectAllFramesReady(object sender, AllFramesReadyEventArgs e) { // Have we already been "shut down" by the user of this viewer, // or has the SkeletonStream been disabled since this event was posted? if ((this.Kinect == null) || !((KinectSensor)sender).SkeletonStream.IsEnabled) { return; } // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", " 0 "); bool haveSkeletonData = false; using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", " 1 "); if (skeletonFrame != null) { if (this.skeletonCanvases == null) { // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", " 2 "); this.CreateListOfSkeletonCanvases(); } if ((this.skeletonData == null) || (this.skeletonData.Length != skeletonFrame.SkeletonArrayLength)) { this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength]; // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", " 3 "); } skeletonFrame.CopySkeletonDataTo(this.skeletonData); haveSkeletonData = true; } } if (haveSkeletonData) { using (DepthImageFrame depthImageFrame = e.OpenDepthImageFrame()) { if (depthImageFrame != null) { // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", " 4 "); int trackedSkeletons = 0; foreach (Skeleton skeleton in this.skeletonData) { if (skeleton.TrackingState == SkeletonTrackingState.Tracked) { // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt","Tracked"); } else if (skeleton.TrackingState == SkeletonTrackingState.PositionOnly) { // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", trackedSkeletons.ToString() + " 10 "); } else if (skeleton.TrackingState == SkeletonTrackingState.NotTracked) { //File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", "Nottrack"); } Dictionary <JointType, JointMapping> jointMapping = this.jointMappings[trackedSkeletons]; jointMapping.Clear(); KinectSkeleton skeletonCanvas = this.skeletonCanvases[trackedSkeletons++]; skeletonCanvas.ShowBones = this.ShowBones; skeletonCanvas.ShowJoints = this.ShowJoints; skeletonCanvas.ShowCenter = this.ShowCenter; int temp = 0; int count1 = 0; float [] data_joint = new float [42]; // Transform the data into the correct space // For each joint, we determine the exact X/Y coordinates for the target view foreach (Joint joint in skeleton.Joints) { // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", " 6 "); Point mappedPoint = this.GetPosition2DLocation(depthImageFrame, joint.Position); jointMapping[joint.JointType] = new JointMapping { Joint = joint, MappedPoint = mappedPoint }; Joint asd = joint; if (asd.TrackingState == JointTrackingState.Tracked && asd != skeleton.Joints[JointType.FootRight] && asd != skeleton.Joints[JointType.FootLeft] && asd != skeleton.Joints[JointType.KneeLeft] && asd != skeleton.Joints[JointType.AnkleLeft] && asd != skeleton.Joints[JointType.KneeRight] && asd != skeleton.Joints[JointType.AnkleRight]) { // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", " j "+ j.ToString()); temp++; // File.AppendAllText(path,p.ToString()+" "+q.ToString()+" " +" "); data_joint[count1] = asd.Position.X; count1++; data_joint[count1] = asd.Position.Y; count1++; data_joint[count1] = asd.Position.Z; count1++; //string text; // text =(asd.Position.Z).ToString()+" "; // WriteAllText creates a file, writes the specified string to the file, // and then closes the file. You do NOT need to call Flush() or Close(). // System.IO.File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", text); // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt",asd.Position.X.ToString() + " " + asd.Position.Y.ToString() + " " + asd.Position.Z.ToString()); // Console.WriteLine(asd.Position.X.ToString() + asd.Position.Y.ToString() + asd.Position.Z.ToString()); } /* else if(j!=1 ) * { * // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", "NONE track"+ count.ToString() + Environment.NewLine); * * //File.AppendAllText(@"C:\Users\pk1601cs33\helll.csv", " -1 -1 -1 "); * j = 0; * }*/ } if (temp == 14) { useless++; /*string path=@"C:\Users\pk1601cs33\exer.csv"; * StringBuilder sbOutput = new StringBuilder(); * for(int j =0 ; j< 42 ; j++) * { * if(j==0) * File.AppendAllText(path,data_joint[j].ToString()); * else * File.AppendAllText(path," "+ data_joint[j].ToString()); * * } * File.AppendAllText(path, Environment.NewLine); */ if (useless >= 10) { useless = 0; Insert(data_joint); } temp = 0; } //File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", Environment.NewLine + count.ToString() + " " +Environment.NewLine); /* if (i == 1) * { * File.AppendAllText(@"C:\Users\pk1601cs33\not_valid.csv",Environment.NewLine); * i = 0; * } */ // button1_Click(null, null); // Look up the center point Point centerPoint = this.GetPosition2DLocation(depthImageFrame, skeleton.Position); // Scale the skeleton thickness // 1.0 is the desired size at 640 width double scale = this.RenderSize.Width / 640; skeletonCanvas.RefreshSkeleton(skeleton, jointMapping, centerPoint, scale); } if (ImageType == ImageType.Depth) { this.ChooseTrackedSkeletons(this.skeletonData); } } } } }
private void KinectAllFramesReady(object sender, AllFramesReadyEventArgs e) { // Have we already been "shut down" by the user of this viewer, // or has the SkeletonStream been disabled since this event was posted? if ((this.Kinect == null) || !((KinectSensor)sender).SkeletonStream.IsEnabled) { return; } // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", " 0 "); bool haveSkeletonData = false; using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", " 1 "); if (skeletonFrame != null) { if (this.skeletonCanvases == null) { // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", " 2 "); this.CreateListOfSkeletonCanvases(); } if ((this.skeletonData == null) || (this.skeletonData.Length != skeletonFrame.SkeletonArrayLength)) { this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength]; // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", " 3 "); } skeletonFrame.CopySkeletonDataTo(this.skeletonData); haveSkeletonData = true; } } if (haveSkeletonData) { using (DepthImageFrame depthImageFrame = e.OpenDepthImageFrame()) { if (depthImageFrame != null) { // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", " 4 "); int trackedSkeletons = 0; foreach (Skeleton skeleton in this.skeletonData) { if (skeleton.TrackingState == SkeletonTrackingState.Tracked) { // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt","Tracked"); } else if (skeleton.TrackingState == SkeletonTrackingState.PositionOnly) { // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", trackedSkeletons.ToString() + " 10 "); } else if (skeleton.TrackingState == SkeletonTrackingState.NotTracked) { //File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", "Nottrack"); } Dictionary <JointType, JointMapping> jointMapping = this.jointMappings[trackedSkeletons]; jointMapping.Clear(); KinectSkeleton skeletonCanvas = this.skeletonCanvases[trackedSkeletons++]; skeletonCanvas.ShowBones = this.ShowBones; skeletonCanvas.ShowJoints = this.ShowJoints; skeletonCanvas.ShowCenter = this.ShowCenter; foreach (Joint joint in skeleton.Joints) { Point mappedPoint = this.GetPosition2DLocation(depthImageFrame, joint.Position); jointMapping[joint.JointType] = new JointMapping { Joint = joint, MappedPoint = mappedPoint }; Joint asd = joint; if (asd.TrackingState == JointTrackingState.Tracked) { Vector3D elbowl = new Vector3D(skeleton.Joints[JointType.ElbowLeft].Position.X, skeleton.Joints[JointType.ElbowLeft].Position.Y, skeleton.Joints[JointType.ElbowLeft].Position.Z); Vector3D WristLeft = new Vector3D(skeleton.Joints[JointType.WristLeft].Position.X, skeleton.Joints[JointType.WristLeft].Position.Y, skeleton.Joints[JointType.WristLeft].Position.Z); Vector3D ShoulderLeft = new Vector3D(skeleton.Joints[JointType.ShoulderLeft].Position.X, skeleton.Joints[JointType.ShoulderLeft].Position.Y, skeleton.Joints[JointType.ShoulderLeft].Position.Z); Vector3D Head = new Vector3D(skeleton.Joints[JointType.ShoulderCenter].Position.X, skeleton.Joints[JointType.ShoulderCenter].Position.Y, skeleton.Joints[JointType.ShoulderCenter].Position.Z); Vector3D Neck = new Vector3D(skeleton.Joints[JointType.Spine].Position.X, skeleton.Joints[JointType.Spine].Position.Y, skeleton.Joints[JointType.Spine].Position.Z); //for two hand Vector3D shoulderright = new Vector3D(skeleton.Joints[JointType.ShoulderRight].Position.X, skeleton.Joints[JointType.ShoulderRight].Position.Y, skeleton.Joints[JointType.ShoulderRight].Position.Z); Vector3D elbowright = new Vector3D(skeleton.Joints[JointType.ElbowRight].Position.X, skeleton.Joints[JointType.ElbowRight].Position.Y, skeleton.Joints[JointType.ElbowRight].Position.Z); //vector for high knees Vector3D ankleleft = new Vector3D(skeleton.Joints[JointType.AnkleLeft].Position.X, skeleton.Joints[JointType.AnkleLeft].Position.Y, skeleton.Joints[JointType.AnkleLeft].Position.Z); Vector3D kneeleft = new Vector3D(skeleton.Joints[JointType.KneeLeft].Position.X, skeleton.Joints[JointType.KneeLeft].Position.Y, skeleton.Joints[JointType.KneeLeft].Position.Z); Vector3D hipleft = new Vector3D(skeleton.Joints[JointType.HipLeft].Position.X, skeleton.Joints[JointType.HipLeft].Position.Y, skeleton.Joints[JointType.HipLeft].Position.Z); //Vector3D SpineShoulder = new Vector3D(skeleton.Joints[JointType.SpineShoulder].Position.X, skeleton.Joints[JointType.SpineShoulder].Position.Y, skeleton.Joints[JointType.SpineShoulder].Position.Z); LeftElbowAngle = AngleBetweenTwoVectors(elbowl - ShoulderLeft, elbowl - WristLeft); rotationAngle = AngleBetweenTwoVectors(elbowl - ShoulderLeft, Neck - Head); rottwohand = AngleBetweenTwoVectors(kneeleft - ankleleft, kneeleft - hipleft); footrot = AngleBetweenTwoVectors(ShoulderLeft - elbowl, shoulderright - elbowright); if (footrot >= 0 && footrot <= 100) { if (tempcount4 == 0) { countnumber4++; } tempcount4 = 1; } else { if (tempcount4 == 1) { // countnumber3++; } tempcount4 = 0; } if (rottwohand >= 0 && rottwohand <= 120) { if (tempcount3 == 0) { countnumber3++; } tempcount3 = 1; } else { if (tempcount3 == 1) { // countnumber3++; } tempcount3 = 0; } if (LeftElbowAngle >= 0 && LeftElbowAngle <= 90) { if (tempcount1 == 0) { countnumber1++; } tempcount1 = 1; } else { if (tempcount1 == 1) { //countnumber1++; } tempcount1 = 0; } if (rotationAngle >= 0 && rotationAngle <= 90) { if (tempcount2 == 0) { countnumber2++; } tempcount2 = 1; } else { if (tempcount2 == 1) { countnumber2++; } tempcount2 = 0; } // double angle=AngleBetweenTwoVectors(ElbowLeft, WristLeft); // Console.WriteLine("angle1 = " + LeftElbowAngle.ToString() + "count1 = " + countnumber1.ToString() + "result1= " + tempcount1.ToString()); // Console.WriteLine("angle2 = " + rotationAngle.ToString() + "count2 = " + countnumber2.ToString() + "result2= " + tempcount2.ToString()); } } // Console.WriteLine("angle1 = " + LeftElbowAngle.ToString() + "ElbowRotation= " + countnumber1.ToString()); // Console.WriteLine("angle2 = " + rotationAngle.ToString() + "LefthandRotation = " + countnumber2.ToString()); //Console.WriteLine("angle3 = " + rottwohand.ToString() + "HighKnees = " + countnumber3.ToString()); Console.WriteLine("angle4 = " + footrot.ToString() + "BothHandSwing = " + (countnumber4 - 1).ToString()); Point centerPoint = this.GetPosition2DLocation(depthImageFrame, skeleton.Position); // Scale the skeleton thickness // 1.0 is the desired size at 640 width double scale = this.RenderSize.Width / 640; skeletonCanvas.RefreshSkeleton(skeleton, jointMapping, centerPoint, scale); } if (ImageType == ImageType.Depth) { this.ChooseTrackedSkeletons(this.skeletonData); } } } } }
private void KinectAllFramesReady(object sender, AllFramesReadyEventArgs e) { // Have we already been "shut down" by the user of this viewer, // or has the SkeletonStream been disabled since this event was posted? if ((this.Kinect == null) || !((KinectSensor)sender).SkeletonStream.IsEnabled) { return; } bool haveSkeletonData = false; using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { if (this.skeletonCanvases == null) { this.CreateListOfSkeletonCanvases(); } if ((this.skeletonData == null) || (this.skeletonData.Length != skeletonFrame.SkeletonArrayLength)) { this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength]; } skeletonFrame.CopySkeletonDataTo(this.skeletonData); haveSkeletonData = true; } } if (haveSkeletonData) { using (DepthImageFrame depthImageFrame = e.OpenDepthImageFrame()) { if (depthImageFrame != null) { int trackedSkeletons = 0; foreach (Skeleton skeleton in this.skeletonData) { Dictionary <JointType, JointMapping> jointMapping = this.jointMappings[trackedSkeletons]; jointMapping.Clear(); KinectSkeleton skeletonCanvas = this.skeletonCanvases[trackedSkeletons++]; skeletonCanvas.ShowBones = this.ShowBones; skeletonCanvas.ShowJoints = this.ShowJoints; skeletonCanvas.ShowCenter = this.ShowCenter; // ***PIAD if (this.enregistrement && skeleton.TrackingState.Equals(SkeletonTrackingState.Tracked) && !firstTracked) { firstTracked = true; decompte = DateTime.Now.AddSeconds(5); enregistrementSquel = new Dictionary <int, Dictionary <JointType, SkeletonPoint> >(); nb_iterations = 1; } if (firstTracked && decompte > DateTime.Now) { this.labelDecompte.Content = (decompte - DateTime.Now).Seconds; } //if (this.enregistrement && firstTracked && skeleton.TrackingState.Equals(SkeletonTrackingState.Tracked) && decompte <= DateTime.Now) //{ // this.labelDecompte.Content = "Enregistrement en cours..."; // //System.Console.WriteLine(skeleton.Joints[JointType.Head].Position.X); // //enregistrementSquel.Add(skeleton); //} // PIAD*** // Transform the data into the correct space // For each joint, we determine the exact X/Y coordinates for the target view Dictionary <JointType, SkeletonPoint> temp = new Dictionary <JointType, SkeletonPoint>(); foreach (Joint joint in skeleton.Joints) { temp.Add(joint.JointType, joint.Position); Point mappedPoint = this.GetPosition2DLocation(depthImageFrame, joint.Position); jointMapping[joint.JointType] = new JointMapping { Joint = joint, MappedPoint = mappedPoint }; } if (this.enregistrement && firstTracked && skeleton.TrackingState.Equals(SkeletonTrackingState.Tracked) && decompte <= DateTime.Now) { this.labelDecompte.Content = "Enregistrement en cours..."; enregistrementSquel.Add(nb_iterations, temp); nb_iterations++; //System.Console.WriteLine(skeleton.Joints[JointType.Head].Position.X); //enregistrementSquel.Add(skeleton); } // Look up the center point Point centerPoint = this.GetPosition2DLocation(depthImageFrame, skeleton.Position); // Scale the skeleton thickness // 1.0 is the desired size at 640 width double scale = this.RenderSize.Width / 640; skeletonCanvas.RefreshSkeleton(skeleton, jointMapping, centerPoint, scale); } if (ImageType == ImageType.Depth) { this.ChooseTrackedSkeletons(this.skeletonData); } } } } }
private void KinectAllFramesReady(object sender, AllFramesReadyEventArgs e) { // Have we already been "shut down" by the user of this viewer, // or has the SkeletonStream been disabled since this event was posted? if ((this.Kinect == null) || !((KinectSensor)sender).SkeletonStream.IsEnabled) { return; } bool haveSkeletonData = false; using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { if (this.skeletonCanvases == null) { this.CreateListOfSkeletonCanvases(); } if ((this.skeletonData == null) || (this.skeletonData.Length != skeletonFrame.SkeletonArrayLength)) { this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength]; } skeletonFrame.CopySkeletonDataTo(this.skeletonData); haveSkeletonData = true; } } if (haveSkeletonData) { using (DepthImageFrame depthImageFrame = e.OpenDepthImageFrame()) { if (depthImageFrame != null) { int trackedSkeletons = 0; foreach (Skeleton skeleton in this.skeletonData) { Dictionary <JointType, JointMapping> jointMapping = this.jointMappings[trackedSkeletons]; jointMapping.Clear(); KinectSkeleton skeletonCanvas = this.skeletonCanvases[trackedSkeletons++]; skeletonCanvas.ShowBones = this.ShowBones; skeletonCanvas.ShowJoints = this.ShowJoints; skeletonCanvas.ShowCenter = this.ShowCenter; // Transform the data into the correct space // For each joint, we determine the exact X/Y coordinates for the target view foreach (Joint joint in skeleton.Joints) { Console.WriteLine("Here they are: " + joint.Position.X + "" + joint.Position.Y + "" + "" + joint.Position.Z); Point mappedPoint = this.GetPosition2DLocation(depthImageFrame, joint.Position); jointMapping[joint.JointType] = new JointMapping { Joint = joint, MappedPoint = mappedPoint }; } // Look up the center point Point centerPoint = this.GetPosition2DLocation(depthImageFrame, skeleton.Position); // Scale the skeleton thickness // 1.0 is the desired size at 640 width double scale = this.RenderSize.Width / 640; skeletonCanvas.RefreshSkeleton(skeleton, jointMapping, centerPoint, scale); } if (ImageType == ImageType.Depth) { this.ChooseTrackedSkeletons(this.skeletonData); } } } } }