void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
        {
            var reference = e.FrameReference.AcquireFrame();

            // Color
            using (var frame = reference.ColorFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    if (viewer.Visualization == Visualization.Color)
                    {
                        viewer.Image = frame.ToBitmap();
                    }
                }
            }

            // Body
            using (var frame = reference.BodyFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    var bodies = frame.Bodies();

                    _userReporter.Update(bodies);

                    Body body = bodies.Closest();



                    if (body != null)
                    {
                        FrameEdges clippedEdges = body.ClippedEdges;

                        viewer.DrawBody(body, 15, Brushes.Red, 8, Brushes.Aqua);

                        _recorder.Update(body);
                        DateTime currentT = DateTime.Now;
                        TimeSpan elapsed  = currentT - startTime;

                        //Stop recording if duration is not default (0) and reached duration
                        if (Application.Current.Properties["duration"].ToString() != "0")
                        {
                            if (elapsed >= duration)
                            {
                                _recorder.IsRecording = false;
                            }
                        }

                        //Update instructions when user reaches edge of frame
                        if (clippedEdges.HasFlag(FrameEdges.Left))
                        {
                            Instructions.Text = "Turn right and walk";
                            if (current == 2)
                            {
                                laps++;
                            }
                            current = 1;
                        }
                        if (clippedEdges.HasFlag(FrameEdges.Right))
                        {
                            Instructions.Text = "Turn left and walk";
                            if (current == 1)
                            {
                                laps++;
                            }
                            current = 2;
                        }
                        if (laps == 3)  //end of exercise. Save node data
                        {
                            Instructions.Text = "You have completed this exercise!";

                            _timer.Stop();

                            if (!dataSaved)
                            {
                                _recorder.Stop();
                                SaveFileDialog dialog = new SaveFileDialog
                                {
                                    Filter = "Excel files|*.csv"
                                };

                                dialog.ShowDialog();

                                if (!string.IsNullOrWhiteSpace(dialog.FileName))
                                {
                                    System.IO.File.Copy(_recorder.Result, dialog.FileName, true);
                                }

                                //Write data for report generation
                                string path = System.IO.Path.Combine(Environment.CurrentDirectory, @"..\..\..\UserData\WalkingReportData.csv");
                                // This text is added only once to the file.
                                if (!File.Exists(path))
                                {
                                    // Record duration and date of exercise
                                    using (StreamWriter sw = File.CreateText(path))
                                    {
                                        sw.WriteLine("ExerciseDuration,Date");
                                        sw.WriteLine(_timer.Elapsed.ToString() + "," + DateTime.Today.ToString("d"));
                                    }
                                }
                                else
                                {
                                    // This text is always added, making the file longer over time
                                    // if it is not deleted.
                                    using (StreamWriter sw = File.AppendText(path))
                                    {
                                        sw.WriteLine(_timer.Elapsed.ToString() + "," + DateTime.Today.ToString("d"));
                                    }
                                }
                                dataSaved = true;
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
        void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
        {
            var reference = e.FrameReference.AcquireFrame();

            // Color
            using (var frame = reference.ColorFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    if (viewer.Visualization == Visualization.Color)
                    {
                        viewer.Image = frame.ToBitmap();
                    }
                }
            }

            // Body
            using (var frame = reference.BodyFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    var bodies = frame.Bodies();

                    _userReporter.Update(bodies);

                    Body body = bodies.Closest();

                    if (body != null)
                    {
                        viewer.DrawBody(body, 15, Brushes.White, 8, Brushes.Aqua);
                        _gesture.Update(body);

                        if (_recorder.IsRecording)
                        {
                            _recorder.Update(body);
                            DateTime currentT = DateTime.Now;
                            TimeSpan elapsed  = currentT - startTime;

                            //Stop recording if duration is not default (0) and reached duration
                            if (Application.Current.Properties["duration"].ToString() != "0")
                            {
                                if (elapsed >= duration)
                                {
                                    _recorder.IsRecording = false;
                                }
                            }
                        }

                        //Display remaining repititions
                        SittingCount.Text = sittingCounter.ToString();

                        Instructions.Text = "Raise your right arm above your head to begin this exercise";
                        if (body.Joints[JointType.HandRight].Position.Y > body.Joints[JointType.Head].Position.Y)
                        {
                            begin = true;
                            //If data recording set to begin at exercise start, start recording when begin
                            if (Application.Current.Properties["beginAtExerciseStart"].ToString() == "True" && !dataSaved && !_recorder.IsRecording)
                            {
                                _recorder.Start();
                            }
                        }

                        if (begin)
                        {
                            // knee height close to hip height
                            if (body.Joints[JointType.HipLeft].Position.Y <= body.Joints[JointType.KneeLeft].Position.Y + .2)
                            {
                                //Update instructions
                                Instructions.Text = "Stand up with your arms forward";
                                if (current == 1)
                                {
                                    sittingCounter--;
                                }
                                current = 2;
                            }
                            else
                            {
                                //Update instructions
                                Instructions.Text = "Sit down with your arms forward";

                                current = 1;
                            }

                            if (sittingCounter == 0)  //end of exercise. Save node data
                            {
                                begin             = false;
                                Instructions.Text = "You have completed this exercise!";

                                _timer.Stop();

                                if (!dataSaved)
                                {
                                    _recorder.Stop();
                                    SaveFileDialog dialog = new SaveFileDialog
                                    {
                                        Filter = "Excel files|*.csv"
                                    };

                                    dialog.ShowDialog();

                                    if (!string.IsNullOrWhiteSpace(dialog.FileName))
                                    {
                                        System.IO.File.Copy(_recorder.Result, dialog.FileName, true);
                                    }


                                    //Write data for report generation
                                    string path = System.IO.Path.Combine(Environment.CurrentDirectory, @"..\..\..\UserData\SittingReportData.csv");
                                    // This text is added only once to the file.
                                    if (!File.Exists(path))
                                    {
                                        // Record duration and date of exercise
                                        using (StreamWriter sw = File.CreateText(path))
                                        {
                                            sw.WriteLine("ExerciseDuration,Date");
                                            sw.WriteLine(_timer.Elapsed.ToString() + "," + DateTime.Today.ToString("d"));
                                        }
                                    }
                                    else
                                    {
                                        // This text is always added, making the file longer over time
                                        // if it is not deleted.
                                        using (StreamWriter sw = File.AppendText(path))
                                        {
                                            sw.WriteLine(_timer.Elapsed.ToString() + "," + DateTime.Today.ToString("d"));
                                        }
                                    }
                                    dataSaved = true;
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #3
0
        void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
        {
            var reference = e.FrameReference.AcquireFrame();

            // Color
            using (var frame = reference.ColorFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    if (viewer.Visualization == Visualization.Color)
                    {
                        viewer.Image = frame.ToBitmap();
                    }
                }
            }

            // Body
            using (var frame = reference.BodyFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    var bodies = frame.Bodies();

                    _userReporter.Update(bodies);

                    Body body = bodies.Closest();

                    if (body != null)
                    {
                        viewer.DrawBody(body, 15, Brushes.White, 8, Brushes.Aqua);
                        // Draw the Arm Angles
                        rightArmAngle.Update(body.Joints[_startRight], body.Joints[_centerRight], body.Joints[_endRight], 100);
                        leftArmAngle.Update(body.Joints[_startLeft], body.Joints[_centerLeft], body.Joints[_endLeft], 100);



                        if (rcounter < startreps && onRightArmRaise)
                        {
                            //If data recording set to begin at exercise start, start recording after first rep
                            if (rcounter == startreps - 1 && Application.Current.Properties["beginAtExerciseStart"].ToString() == "True" && !dataSaved && !_recorder.IsRecording)
                            {
                                _recorder.Start();
                            }
                        }

                        _gesture.Update(body);
                        _gesture2.Update(body);

                        if (_recorder.IsRecording)
                        {
                            _recorder.Update(body);

                            DateTime current = DateTime.Now;
                            TimeSpan elapsed = current - startTime;

                            //Stop recording if duration is not default (0) and reached duration
                            if (Application.Current.Properties["duration"].ToString() != "0")
                            {
                                if (elapsed >= duration)
                                {
                                    _recorder.IsRecording = false;
                                }
                            }
                        }


                        if (onRightArmRaise)
                        {
                            Instructions.Text = "Raise your right arm above your head";
                            //Display remaining repititions
                            ArmRaiseCount.Text = rcounter.ToString();
                            //Display arm angle value
                            tblAngle.Text = ((int)rightArmAngle.Angle).ToString();
                        }
                        else
                        {
                            //Update instructions
                            Instructions.Text = "Raise your left arm above your head";
                            //Display arm angle value
                            pageTitle.Text = "Left Arm Angle:";
                            tblAngle.Text  = ((int)leftArmAngle.Angle).ToString();
                            //Display remaining repetitions
                            ArmRaiseCount.Text = lcounter.ToString();
                        }
                        if (lcounter == 0)  //end of exercise. Save node data
                        {
                            Instructions.Text = "You have completed this exercise!";

                            _timer.Stop();

                            if (!dataSaved)
                            {
                                _recorder.Stop();
                                SaveFileDialog dialog = new SaveFileDialog
                                {
                                    Filter = "Excel files|*.csv"
                                };

                                dialog.ShowDialog();

                                if (!string.IsNullOrWhiteSpace(dialog.FileName))
                                {
                                    System.IO.File.Copy(_recorder.Result, dialog.FileName, true);
                                }

                                //Write data for report generation
                                string path = Path.Combine(Environment.CurrentDirectory, @"..\..\..\UserData\ArmRaisesReportData.csv");
                                // This text is added only once to the file.
                                if (!File.Exists(path))
                                {
                                    // Record duration and date of exercise
                                    using (StreamWriter sw = File.CreateText(path))
                                    {
                                        sw.WriteLine("ExerciseDuration,Date");
                                        sw.WriteLine(_timer.Elapsed.ToString() + "," + DateTime.Today.ToString("d"));
                                    }
                                }

                                // This text is always added, making the file longer over time
                                // if it is not deleted.
                                else
                                {
                                    using (StreamWriter sw = File.AppendText(path))
                                    {
                                        sw.WriteLine(_timer.Elapsed.ToString() + "," + DateTime.Today.ToString("d"));
                                    }
                                }
                                dataSaved = true;
                            }
                        }
                    }
                }
            }
        }