Example #1
0
        void kinect_skeletonframe_ready(object sender, SkeletonFrameReadyEventArgs e)
        {

            using (SkeletonFrame frame = e.OpenSkeletonFrame())
            {
                if (frame == null)
                    return;

                // get skeleton data
                Skeleton[] skeletons = new Skeleton[frame.SkeletonArrayLength];
                frame.CopySkeletonDataTo(skeletons);

                // get first tracked skeleton
                Skeleton tracked_skeleton = null;
                foreach (Skeleton ske in skeletons)
                {
                    if (ske.TrackingState == SkeletonTrackingState.Tracked)
                    {
                        tracked_skeleton = ske;
                        break;
                    }
                }

                if (tracked_skeleton == null)
                    return;

                gesture_capture_data.Add(tracked_skeleton);


                if (kinect_data_manager.ifShowJointStatus)
                {
                    // update status
                    motion_assessor.UpdateJointStatus(tracked_skeleton, toMeasureUnits);
                    kinect_data_manager.cur_joint_status = motion_assessor.GetCurrentJointStatus();
                    kinect_data_manager.toMeasureUnits = this.toMeasureUnits;
                    //Joint primaryHand = GetPrimaryHand(tracked_skeleton);
                    //TrackHand(primaryHand);
                    //ButtonPressed(tracked_skeleton);

                    // show feedback
                    //feedback_textblock.Text = motion_assessor.GetFeedbackForCurrentStatus();
                }

                kinect_data_manager.UpdateSkeletonData(tracked_skeleton);


            }
        }
        void kinect_skeletonframe_ready(object sender, SkeletonFrameReadyEventArgs e)
        {
            using (SkeletonFrame frame = e.OpenSkeletonFrame())
            {
                if (frame == null)
                {
                    return;
                }

                // get skeleton data
                Skeleton[] skeletons = new Skeleton[frame.SkeletonArrayLength];
                frame.CopySkeletonDataTo(skeletons);

                // get first tracked skeleton
                Skeleton tracked_skeleton = null;
                foreach (Skeleton ske in skeletons)
                {
                    if (ske.TrackingState == SkeletonTrackingState.Tracked)
                    {
                        tracked_skeleton = ske;
                        break;
                    }
                }

                if (tracked_skeleton == null)
                {
                    return;
                }

                // if capturing, add to gesture data
                if (gestureCaptureBtn.Content.ToString() == "Stop Capture")
                {
                    // just add first tracked skeleton, assume only one person is present
                    gesture_capture_data.Add(tracked_skeleton);
                }

                if (isRecognition)
                {
                    #region update_gesture_data

                    if (temp_gesture.data.Count >= gesture_recognizer.gesture_max_len)
                    {
                        temp_gesture.data.RemoveAt(0);
                        Debug.WriteLine("Remove frame.");
                    }

                    temp_gesture.data.Add(tracked_skeleton);
                    Debug.WriteLine("Add frame:" + temp_gesture.data.Count.ToString());

                    #endregion


                    if (temp_gesture.data.Count >= gesture_recognizer.gesture_min_len / 2 &&
                        temp_gesture.data.Count <= gesture_recognizer.gesture_max_len * 2)
                    {
                        // reset
                        gesture_match_scorebar.Value = gesture_match_scorebar.Maximum;
                        recDistLabel.Content         = gesture_match_scorebar.Maximum;
                        rec_res_label.Content        = "Unknown";
                        Debug.WriteLine("reset");

                        Debug.WriteLine("Do recognition.");

                        // do recognition
                        string res  = "";
                        double dist = gesture_recognizer.MatchToDatabase(temp_gesture, out res);
                        gesture_match_scorebar.Value =
                            (double.IsInfinity(dist) ? gesture_match_scorebar.Maximum : dist);
                        if (dist >= 0 && dist <= 20)
                        {
                            rec_res_label.Content        = res;
                            last_detection_label.Content = res;
                            temp_gesture.data.Clear();
                            Debug.WriteLine("Detected");
                        }
                        else
                        {
                            rec_res_label.Content = "Unknown";
                        }

                        recDistLabel.Content = dist.ToString();
                    }
                }

                if (kinect_data_manager.ifShowJointStatus)
                {
                    // update status
                    //motion_assessor.UpdateJointStatus(tracked_skeleton);
                    kinect_data_manager.cur_joint_status = motion_assessor.GetCurrentJointStatus();

                    // show feedback
                    //feedback_textblock.Text = motion_assessor.GetFeedbackForCurrentStatus();
                }

                kinect_data_manager.UpdateSkeletonData(tracked_skeleton);

                if (saveVideoCheckBox.IsChecked.Value)
                {
                    // write screen shot of display into video file
                    int width  = (int)groupBox3.Width + 20;
                    int height = (int)groupBox3.Height + 20;
                    System.Drawing.Rectangle bounds = new System.Drawing.Rectangle(
                        (int)(Application.Current.MainWindow.Left + groupBox3.Margin.Left),
                        (int)(Application.Current.MainWindow.Top + groupBox3.Margin.Top),
                        width, height);
                    Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height);

                    using (Graphics g = Graphics.FromImage(bitmap))
                    {
                        g.CopyFromScreen(new System.Drawing.Point(bounds.Left, bounds.Top),
                                         new System.Drawing.Point(-1, -1), bounds.Size);
                    }

                    frame_rec_buffer.Add(bitmap);
                }
            }
        }
Example #3
0
        void kinect_skeletonframe_ready(object sender, SkeletonFrameReadyEventArgs e)
        {
            using (SkeletonFrame frame = e.OpenSkeletonFrame())
            {
                if (frame == null)
                {
                    return;
                }

                // get skeleton data
                Skeleton[] skeletons = new Skeleton[frame.SkeletonArrayLength];
                frame.CopySkeletonDataTo(skeletons);

                // get first tracked skeleton
                Skeleton tracked_skeleton = null;
                foreach (Skeleton ske in skeletons)
                {
                    if (ske.TrackingState == SkeletonTrackingState.Tracked)
                    {
                        tracked_skeleton = ske;
                        break;
                    }
                }

                if (tracked_skeleton == null)
                {
                    return;
                }

                // if capturing, add to gesture data
                if (gestureCaptureBtn.Content.ToString() == "Stop Capture")
                {
                    // just add first tracked skeleton, assume only one person is present
                    gesture_capture_data.Add(tracked_skeleton);
                }

                if (kinect_data_manager.ifShowJointStatus)
                {
                    // update status
                    motion_assessor.UpdateJointStatus(tracked_skeleton, toMeasureUnits);
                    kinect_data_manager.cur_joint_status = motion_assessor.GetCurrentJointStatus();
                    kinect_data_manager.toMeasureUnits   = this.toMeasureUnits;

                    // show feedback
                    //feedback_textblock.Text = motion_assessor.GetFeedbackForCurrentStatus();
                }

                kinect_data_manager.UpdateSkeletonData(tracked_skeleton);

                if (saveVideoCheckBox.IsChecked.Value)
                {
                    // save skeleton data
                    gesture_capture_data.Add(tracked_skeleton);

                    // write screen shot of display into video file
                    int width  = (int)groupBox3.Width + 20;
                    int height = (int)groupBox3.Height + 20;
                    System.Drawing.Rectangle bounds = new System.Drawing.Rectangle(
                        (int)(Application.Current.MainWindow.Left + groupBox3.Margin.Left),
                        (int)(Application.Current.MainWindow.Top + groupBox3.Margin.Top),
                        width, height);
                    Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height);

                    using (Graphics g = Graphics.FromImage(bitmap))
                    {
                        g.CopyFromScreen(new System.Drawing.Point(bounds.Left, bounds.Top),
                                         new System.Drawing.Point(-1, -1), bounds.Size);
                    }

                    overlap_frame_rec_buffer.Add(bitmap);
                }
            }
        }