Example #1
0
        void UpdateSkeletonDisplay(ReplaySkeletonFrame frame)
        {
            if (frame.Skeletons == null)
            {
                return;
            }
            Dictionary <int, string> stabilities = new Dictionary <int, string>();

            foreach (var skeleton in frame.Skeletons)
            {
                if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                {
                    continue;
                }

                contextTracker.Add(skeleton.Position.ToVector3(), skeleton.TrackingId);
                stabilities.Add(skeleton.TrackingId,
                                contextTracker.IsStableRelativeToCurrentSpeed(skeleton.TrackingId) ?
                                "Stable" : "Non stable");
            }

            try {
                if (viewSkeleton && skeletonDisplayManager != null)
                {
                    skeletonDisplayManager.Draw(frame.Skeletons, false,
                                                HandInputParams.ColorImageFormat);
                }
                else
                {
                    skeletonCanvas.Children.Clear();
                }
            } catch (Exception e) {
                Log.Error(e.Message);
            }
        }
Example #2
0
        void ReplayFrame(ReplayDepthImageFrame df, ReplayColorImageFrame cf,
                         ReplaySkeletonFrame sf)
        {
            if (df != null)
            {
                labelFrameNumber.Content = df.FrameNumber.ToString();
                if (gtReplayer != null)
                {
                    var data = gtReplayer.GetDataFrame(df.FrameNumber);
                    if (data != null)
                    {
                        UpdateGroundTruthDisplay(data);
                    }
                }
            }
            colorManager.Update(cf, !displayDebug);
            depthManager.Update(df);
            UpdateSkeletonDisplay(sf);
            if (handTracker != null && recogEngine != null)
            {
                var result = handTracker.Update(depthManager.PixelData, colorManager.PixelData,
                                                SkeletonUtil.FirstTrackedSkeleton(sf.Skeletons));
                var gesture = recogEngine.Update(result, viewHog);

                lock (inputServer)
                    inputServer.Send(gesture);

                textGestureEvent.Text = gesture;
                fpsCounter.LogFPS();
                UpdateDisplay(result);
            }
        }
Example #3
0
        public void Draw(ReplaySkeletonFrame frame)
        {
            rootCanvas.Children.Clear();
            foreach (ReplaySkeletonData skeleton in frame.Skeletons)
            {
                if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                {
                    continue;
                }

                Plot(JointID.HandLeft, skeleton.Joints);
                Trace(JointID.HandLeft, JointID.WristLeft, skeleton.Joints);
                Plot(JointID.WristLeft, skeleton.Joints);
                Trace(JointID.WristLeft, JointID.ElbowLeft, skeleton.Joints);
                Plot(JointID.ElbowLeft, skeleton.Joints);
                Trace(JointID.ElbowLeft, JointID.ShoulderLeft, skeleton.Joints);
                Plot(JointID.ShoulderLeft, skeleton.Joints);
                Trace(JointID.ShoulderLeft, JointID.ShoulderCenter, skeleton.Joints);
                Plot(JointID.ShoulderCenter, skeleton.Joints);

                Trace(JointID.ShoulderCenter, JointID.Head, skeleton.Joints);

                Plot(JointID.Head, JointID.ShoulderCenter, skeleton.Joints);

                Trace(JointID.ShoulderCenter, JointID.ShoulderRight, skeleton.Joints);
                Plot(JointID.ShoulderRight, skeleton.Joints);
                Trace(JointID.ShoulderRight, JointID.ElbowRight, skeleton.Joints);
                Plot(JointID.ElbowRight, skeleton.Joints);
                Trace(JointID.ElbowRight, JointID.WristRight, skeleton.Joints);
                Plot(JointID.WristRight, skeleton.Joints);
                Trace(JointID.WristRight, JointID.HandRight, skeleton.Joints);
                Plot(JointID.HandRight, skeleton.Joints);

                Trace(JointID.ShoulderCenter, JointID.Spine, skeleton.Joints);
                Plot(JointID.Spine, skeleton.Joints);
                Trace(JointID.Spine, JointID.HipCenter, skeleton.Joints);
                Plot(JointID.HipCenter, skeleton.Joints);

                Trace(JointID.HipCenter, JointID.HipLeft, skeleton.Joints);
                Plot(JointID.HipLeft, skeleton.Joints);
                Trace(JointID.HipLeft, JointID.KneeLeft, skeleton.Joints);
                Plot(JointID.KneeLeft, skeleton.Joints);
                Trace(JointID.KneeLeft, JointID.AnkleLeft, skeleton.Joints);
                Plot(JointID.AnkleLeft, skeleton.Joints);
                Trace(JointID.AnkleLeft, JointID.FootLeft, skeleton.Joints);
                Plot(JointID.FootLeft, skeleton.Joints);

                Trace(JointID.HipCenter, JointID.HipRight, skeleton.Joints);
                Plot(JointID.HipRight, skeleton.Joints);
                Trace(JointID.HipRight, JointID.KneeRight, skeleton.Joints);
                Plot(JointID.KneeRight, skeleton.Joints);
                Trace(JointID.KneeRight, JointID.AnkleRight, skeleton.Joints);
                Plot(JointID.AnkleRight, skeleton.Joints);
                Trace(JointID.AnkleRight, JointID.FootRight, skeleton.Joints);
                Plot(JointID.FootRight, skeleton.Joints);
            }
        }
Example #4
0
        /// <summary>
        /// On replay skeleton event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ReplaySkeletonFrameReady(object sender, ReplaySkeletonFrameReadyEventArgs e)
        {
            ReplaySkeletonFrame replaySkeletonFrame = e.SkeletonFrame;

            if (replaySkeletonFrame == null)
            {
                return;
            }

            //this.SkeletonDisplayManager.Draw(replaySkeletonFrame.Skeletons, false);
        }
Example #5
0
        private void UpdateSkeletons(ReplaySkeletonFrame frame)
        {
            _skeletons = frame.Skeletons;
            var trackedSkeleton = _skeletons.FirstOrDefault(s => s.TrackingState == SkeletonTrackingState.Tracked);

            if (trackedSkeleton == null)
            {
                return;
            }

            DrawJoints(trackedSkeleton);
        }
Example #6
0
        void ProcessFrame(ReplaySkeletonFrame frame)
        {
            Dictionary <int, string> stabilities = new Dictionary <int, string>();

            foreach (var skeleton in frame.Skeletons)
            {
                if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                {
                    continue;
                }

                barycenterHelper.Add(skeleton.Position.ToVector3(), skeleton.TrackingID);

                stabilities.Add(skeleton.TrackingID, barycenterHelper.IsStable(skeleton.TrackingID) ? "Stable" : "Unstable");
                if (!barycenterHelper.IsStable(skeleton.TrackingID))
                {
                    continue;
                }

                if (recordNextFrameForPosture)
                {
                    recordNextFrameForPosture = false;
                    templatePostureDetector.AddTemplate(skeleton);
                }

                foreach (Joint joint in skeleton.Joints)
                {
                    if (joint.Position.W < 0.8f || joint.TrackingState != JointTrackingState.Tracked)
                    {
                        continue;
                    }

                    if (joint.ID == JointID.HandRight)
                    {
                        swipeGestureRecognizer.Add(joint.Position, kinectRuntime.SkeletonEngine);
                        circleGestureRecognizer.Add(joint.Position, kinectRuntime.SkeletonEngine);
                    }
                }

                algorithmicPostureRecognizer.TrackPostures(skeleton);
                templatePostureDetector.TrackPostures(skeleton);
            }

            skeletonDisplayManager.Draw(frame);

            stabilitiesList.ItemsSource = stabilities;

            currentPosture.Text = "Current posture: " + algorithmicPostureRecognizer.CurrentPosture.ToString();
        }
Example #7
0
        public void synchronize(
            ReplayDepthImageFrame depthFrame,
            ReplayColorImageFrame colorFrame,
            ReplaySkeletonFrame skletonFrame,
            Boolean isPauseMode
            )
        {
            IsPauseMode = isPauseMode;
            colorFrame.CopyPixelDataTo(_colorByte);
            depthFrame.CopyPixelDataTo(_depthShort);
            for (int i = 0; i < _pixelDepthDataLength; i++)
            {
                _depthByte[i] = (byte)(_depthShort[i] * 0.064 - 1);
            }

            _isCreation        = true;
            IsSkeletonDetected = skletonFrame.IsSkeletonDetected;

            if (skletonFrame.IsSkeletonDetected)
            {
                UserSkeleton[SkeletonDataType.RIGHT_HAND] = new Point(
                    skletonFrame.RightHandPositionX,
                    skletonFrame.RightHandPositionY
                    );

                UserSkeleton[SkeletonDataType.LEFT_HAND] = new Point(
                    skletonFrame.LeftHandPositionX,
                    skletonFrame.LeftHandPositionY
                    );

                UserSkeleton[SkeletonDataType.SPINE] = new Point(
                    skletonFrame.SpinePositionX,
                    skletonFrame.SpinePositionY
                    );
            }
            _isCreation = false;
        }
Example #8
0
        internal void AddFrames(BinaryReader reader)
        {
            //not the best of approaches - assuming that color frame is the 1st frame followed by depth and skeleton frame
            while (reader.BaseStream.Position < reader.BaseStream.Length)
            {
                var header = (FrameType)reader.ReadInt32();
                switch (header)
                {
                case FrameType.Color:
                    var colorFrame = new ReplayColorImageFrame();
                    colorFrame.CreateFromReader(reader);
                    frames.Add(new ReplayAllFrames {
                        ColorImageFrame = colorFrame
                    });
                    break;

                case FrameType.Depth:

                    var depthFrame = new ReplayDepthImageFrame();
                    depthFrame.CreateFromReader(reader);
                    if (frames.Any())
                    {
                        frames.Last().DepthImageFrame = depthFrame;
                    }
                    break;

                case FrameType.Skeletons:
                    var skeletonFrame = new ReplaySkeletonFrame();
                    skeletonFrame.CreateFromReader(reader);
                    if (frames.Any())
                    {
                        frames.Last().SkeletonFrame = skeletonFrame;
                    }
                    break;
                }
            }
        }
        void ProcessFrame(ReplaySkeletonFrame frame)
        {
            Dictionary <int, string> stabilities = new Dictionary <int, string>();

            foreach (var skeleton in frame.Skeletons)
            {
                if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                {
                    continue;
                }

                contextTracker.Add(skeleton.Position.ToVector3(), skeleton.TrackingId);
                stabilities.Add(skeleton.TrackingId, contextTracker.IsStableRelativeToCurrentSpeed(skeleton.TrackingId) ? "Stable" : "Non stable");
                if (!contextTracker.IsStableRelativeToCurrentSpeed(skeleton.TrackingId))
                {
                    continue;
                }

                foreach (Joint joint in skeleton.Joints) //오른손기능구현부
                {
                    if (joint.TrackingState != JointTrackingState.Tracked)
                    {
                        continue;
                    }

                    if (joint.JointType == JointType.HandRight)
                    {
                        circleGestureRecognizer.Add(joint.Position, kinectSensor);
                        triangleGestureRecognizer.Add(joint.Position, kinectSensor);
                        //Add Triangle
                        switch (swipeGestureRecognizer.icon_bit)
                        {
                        case 0:
                            if (swipeGestureRecognizer.cir_bit == 0x01)     //브라우져 영역
                            {
                                controlMouse.IsChecked  = true;
                                Browser_grid.Visibility = Visibility.Visible;
                            }
                            break;

                        case 1:
                            if (swipeGestureRecognizer.cir_bit == 0x01)     //빙맵 영역
                            {
                                BingMap_Loaded();
                            }
                            break;

                        case 2:
                            if (swipeGestureRecognizer.cir_bit == 0x01)
                            {
                                gdDoc.Visibility = Visibility.Visible;
                                btnDocument_Click();
                                PPT_Loaded();     //추가
                            }
                            break;

                        case 3:
                            if (swipeGestureRecognizer.cir_bit == 0x01)     //미디어 영역
                            {
                                Media_Loaded();
                            }
                            break;

                        case 4:
                            if (swipeGestureRecognizer.cir_bit == 0x01)
                            {
                                gdPicture.Visibility = Visibility.Visible;

                                if (swipeGestureRecognizer.cir_bit == 0x03)
                                {      //처음 서클비트가 1이들어가 그냥출력하게 해봄
                                    swipeGestureRecognizer.pic_bit = 0;
                                    gdPicture.Visibility           = Visibility.Hidden;
                                    gdPicture.Visibility           = Visibility.Visible;
                                    btnPicture_Click();
                                }
                                else
                                {
                                    btnPicture_Click();
                                }
                            }
                            break;

                        case 5:
                            if (swipeGestureRecognizer.cir_bit == 0x01)
                            {
                                gdVideo.Visibility = Visibility.Visible;
                                btnVideo_Click();
                            }
                            break;

                        default:

                            break;
                        }
                    }
                    else if (joint.JointType == JointType.HandLeft) //왼손 구현부
                    {
                        swipeGestureRecognizer.Add(joint.Position, kinectSensor);
                        if (controlMouse.IsChecked == true)
                        {
                            MouseController.Current.SetHandPosition(kinectSensor, joint, skeleton);
                        }

                        //sw1 = pic_bit;


                        switch (swipeGestureRecognizer.sw_bit) //프로세스 영역 죽이는 구현부
                        {
                        case 0x01:
                            controlMouse.IsChecked  = false;
                            Browser_grid.Visibility = Visibility.Hidden;     //인터넷창 없앰

                            foreach (Process p in Process.GetProcessesByName("iexplore"))
                            {
                                p.Kill();
                            }
                            foreach (Process p in Process.GetProcessesByName("wmplayer"))      //추가
                            {
                                p.Kill();
                            }

                            swipeGestureRecognizer.cir_bit = 0x00;     // Swipe Up 에 의한 Cir_bit의 초기화
                            break;

                        //Internet Swipe_Up => Run.... 닫기 동작에 대한 정의
                        case 0x02:
                            swipeGestureRecognizer.cir_bit = 0x00;
                            break;

                        //Bing Map => Run....
                        case 0x04:

                            gdDoc.Visibility = Visibility.Hidden;
                            foreach (Process p in Process.GetProcessesByName("POWERPNT"))
                            {
                                p.Kill();
                            }

                            swipeGestureRecognizer.cir_bit = 0x00;
                            break;

                        case 0x08:                                                        // Media Ended
                            foreach (Process p in Process.GetProcessesByName("wmplayer")) //추가
                            {
                                p.Kill();
                            }
                            swipeGestureRecognizer.cir_bit = 0x00;
                            break;

                        case 0x10:
                            gdPicture.Visibility           = Visibility.Hidden;
                            swipeGestureRecognizer.cir_bit = 0x00;
                            break;

                        case 0x20:
                            foreach (Process p in Process.GetProcessesByName("wmplayer"))      //추가
                            {
                                p.Kill();
                            }
                            gdVideo.Visibility             = Visibility.Hidden;
                            swipeGestureRecognizer.cir_bit = 0x00;
                            break;
                        }
                    }
                }

                algorithmicPostureRecognizer.TrackPostures(skeleton);
                templatePostureDetector.TrackPostures(skeleton);

                if (recordNextFrameForPosture)
                {
                    templatePostureDetector.AddTemplate(skeleton);
                    recordNextFrameForPosture = false;
                }
            }

            //skeletonDisplayManager.Draw(frame.Skeletons, seatedMode.IsChecked == true);

            stabilitiesList.ItemsSource = stabilities;
        }
Example #10
0
 void ProcessFrame(ReplaySkeletonFrame frame)
 {
     SkeletonDisplayManager.Draw(frame.Skeletons, Models.Settings.SeatedMode);
 }
Example #11
0
        void ProcessFrame(ReplaySkeletonFrame frame)
        {
            Dictionary <int, string> stabilities = new Dictionary <int, string>();

            foreach (var skeleton in frame.Skeletons)
            {
                if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                {
                    continue;
                }

                //if (eyeTracker == null)
                //    eyeTracker = new EyeTracker(kinectSensor);

                //eyeTracker.Track(skeleton);

                contextTracker.Add(skeleton.Position.ToVector3(), skeleton.TrackingId);
                stabilities.Add(skeleton.TrackingId, contextTracker.IsStableRelativeToCurrentSpeed(skeleton.TrackingId) ? "Stable" : "Non stable");
                if (!contextTracker.IsStableRelativeToCurrentSpeed(skeleton.TrackingId))
                {
                    continue;
                }

                //if (eyeTracker.IsLookingToSensor.HasValue && eyeTracker.IsLookingToSensor == false)
                //    continue;

                foreach (Joint joint in skeleton.Joints)
                {
                    if (joint.TrackingState != JointTrackingState.Tracked)
                    {
                        continue;
                    }

                    if (joint.JointType == JointType.HandRight)
                    {
                        circleGestureRecognizer.Add(joint.Position, kinectSensor);
                    }
                    else if (joint.JointType == JointType.HandLeft)
                    {
                        swipeGestureRecognizer.Add(joint.Position, kinectSensor);
                        if (controlMouse.IsChecked == true)
                        {
                            MouseController.Current.SetHandPosition(kinectSensor, joint, skeleton);
                        }
                    }
                }

                algorithmicPostureRecognizer.TrackPostures(skeleton);
                templatePostureDetector.TrackPostures(skeleton);

                if (recordNextFrameForPosture)
                {
                    templatePostureDetector.AddTemplate(skeleton);
                    recordNextFrameForPosture = false;
                }
            }

            skeletonDisplayManager.Draw(frame.Skeletons, seatedMode.IsChecked == true);

            stabilitiesList.ItemsSource = stabilities;
        }
Example #12
0
        private void ProcessFrame(ColorImageFrame colorFrame, DepthImageFrame depthFrame, ReplaySkeletonFrame skeletonFrame)
        {
            Dictionary <int, string> stabilities = new Dictionary <int, string>();

            foreach (var skeleton in skeletonFrame.Skeletons)
            {
                if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                {
                    continue;
                }

                contextTracker.Add(skeleton.Position.ToVector3(), skeleton.TrackingId);
                stabilities.Add(skeleton.TrackingId, contextTracker.IsStableRelativeToCurrentSpeed(skeleton.TrackingId) ? "Stable" : "Non stable");
                if (!contextTracker.IsStableRelativeToCurrentSpeed(skeleton.TrackingId))
                {
                    continue;
                }

                SkeletonPoint center = skeleton.Position;
                foreach (Joint joint in skeleton.Joints)
                {
                    if (joint.JointType == JointType.HandLeft)
                    {
                        if (center.Z - joint.Position.Z > 0.25)
                        {
                            OnGestureDetected(GestureType.LeftInFront.ToString(), center.Z - joint.Position.Z);
                        }
                    }
                    else if (joint.JointType == JointType.HandRight)
                    {
                        if (center.Z - joint.Position.Z > 0.25)
                        {
                            OnGestureDetected(GestureType.RightInFront.ToString(), center.Z - joint.Position.Z);
                        }
                    }
                }

                if (EnsureHeadTracker())
                {
                    byte[] colorImage = new byte[colorFrame.PixelDataLength];
                    colorFrame.CopyPixelDataTo(colorImage);
                    short[] depthImage = new short[depthFrame.PixelDataLength];
                    depthFrame.CopyPixelDataTo(depthImage);
                    var result = HeadTracker.Track(colorFrame.Format, colorImage, depthFrame.Format, depthImage, skeleton);
                    if (result.TrackSuccessful)
                    {
                        if (FaceTracked != null)
                        {
                            FaceTracked(this, new FaceTrackedEventArgs()
                            {
                                Pitch = result.Rotation.X,
                                Roll  = result.Rotation.Z,
                                Yaw   = result.Rotation.Y
                            });
                        }
                    }
                }
            }
        }
Example #13
0
 void ProcessFrame(ReplaySkeletonFrame frame)
 {
     //skeletonDisplayManager.Draw(frame.Skeletons, seatedMode.IsChecked == true);
 }
Example #14
0
        void ProcessFrame(ReplaySkeletonFrame frame)
        {
            Dictionary <int, string> stabilities = new Dictionary <int, string>();

            foreach (var skeleton in frame.Skeletons)
            {
                StringBuilder strBuilder = new StringBuilder();

                if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                {
                    continue;
                }

                //timer for recording and wait
                if (!timerWait.IsRunning && (timerRec.Elapsed.Seconds > 2 || !timerRec.IsRunning))
                {
                    timerRec.Stop();
                    timerRec.Reset();
                    //Console.WriteLine("Please wait while we process the gesture......");
                    //strBuilder.Append("Please wait while we process the gesture......\n");
                    ProcessGesture();
                    timerWait.Reset();
                    timerWait.Start();
                }
                if (timerWait.Elapsed.Seconds >= 5 && !timerRec.IsRunning)
                {
                    //Console.WriteLine("Gesture recorded, NEXT GESTURE!");
                    //strBuilder.Append("Gesture recorded, NEXT GESTURE!\n");
                    timerWait.Stop();
                    timerRec.Start();
                }

                /*contextTracker.Add(skeleton.Position.ToVector3(), skeleton.TrackingId);
                 * stabilities.Add(skeleton.TrackingId, contextTracker.IsStableRelativeToCurrentSpeed(skeleton.TrackingId) ? "Stable" : "Non stable");
                 * if (!contextTracker.IsStableRelativeToCurrentSpeed(skeleton.TrackingId))
                 *  continue;
                 */
                bool touchedLeft  = false;
                bool touchedRight = false;
                foreach (Joint joint in skeleton.Joints)
                {
                    if (status == RecordingStatus.STOP)
                    {
                        break;
                    }

                    if (!timerRec.IsRunning)
                    {
                        continue;
                    }

                    if (m_useGestureLocked && (System.DateTime.Now >= m_timeToEndAt))
                    {
                        strBuilder.Append("Unlocking");
                        m_useGestureLocked = false;
                        break;
                    }
                    else if (m_useGestureLocked)
                    {
                        strBuilder.Append("Locked - " + m_gestureLockMessage);
                        break;
                    }

                    if (joint.TrackingState != JointTrackingState.Tracked)
                    {
                        continue;
                    }
                    //strBuilder.Append(joint.JointType.ToString());

                    if (status == RecordingStatus.RECORD)
                    {
                        if (joint.JointType.Equals(JointType.HandRight))
                        {
                            Console.WriteLine(String.Format("Right [{0}, {1}, {2}]", joint.Position.X, joint.Position.Y, joint.Position.Z));
                            strBuilder.Append(String.Format("\nRight [{0}, {1}, {2}]", joint.Position.X, joint.Position.Y, joint.Position.Z));
                            rightList.Add(new CoordinateContainer(joint.Position.X, joint.Position.Y));
                        }
                        else if (joint.JointType.Equals(JointType.HandLeft))
                        {
                            Console.WriteLine(String.Format("Left [{0}, {1}, {2}]", joint.Position.X, joint.Position.Y, joint.Position.Z));
                            strBuilder.Append(String.Format("\nLeft [{0}, {1}, {2}]", joint.Position.X, joint.Position.Y, joint.Position.Z));
                            leftList.Add(new CoordinateContainer(joint.Position.X, joint.Position.Y));
                        }
                    }
                    else if (status == RecordingStatus.USE)
                    {
                        double cur_pos = joint.Position.Y;
                        if (joint.JointType.Equals(JointType.HandRight))
                        {
                            //Console.WriteLine(String.Format("Using right: [{0}, {1}]", joint.Position.X, joint.Position.Y));
                            //strBuilder.Append(String.Format("\nUsing right: [{0}, {1}]", joint.Position.X, joint.Position.Y));
                            //assume gesture array have only 6 elements
                            int rightIndex = 0;
                            foreach (CoordinateContainer container in gesture1_right)
                            {
                                touchedRight |= IsWithinRange(joint.Position.Y, container.getY()) || IsWithinRange(joint.Position.X, container.getX());
                                if (touchedRight)
                                {
                                    m_rightIndex = rightIndex;
                                    break;
                                }
                                rightIndex++;
                            }
                            if (touchedRight)
                            {
                                if (m_rightIndex != -1)
                                {
                                    Console.WriteLine("Right Hand gesture detected " + gesture1_right[m_rightIndex].name);
                                }
                                //strBuilder.Append("\nRight Hand gesture detected");
                            }
                        }
                        else if (joint.JointType.Equals(JointType.HandLeft))
                        {
                            //Console.WriteLine(String.Format("Using left: [{0}, {1}]", joint.Position.X, joint.Position.Y));
                            //strBuilder.Append(String.Format("\nUsing left: [{0}, {1}]", joint.Position.X, joint.Position.Y));
                            //assume gesture array have only 6 elements
                            int leftIndex = 0;
                            foreach (CoordinateContainer container in gesture1_left)
                            {
                                touchedLeft |= IsWithinRange(joint.Position.Y, container.getY()) || IsWithinRange(joint.Position.X, container.getX());
                                if (touchedLeft)
                                {
                                    m_leftIndex = leftIndex;
                                    break;
                                }
                                leftIndex++;
                            }
                            if (touchedLeft)
                            {
                                if (m_leftIndex != -1)
                                {
                                    Console.WriteLine("Left Hand gesture detected " + gesture1_left[m_leftIndex].name);
                                }
                                //strBuilder.Append("\nLeft Hand gesture detected");
                            }
                        }

                        //if a gesture was discovered, lock for time buffer
                        if (m_rightIndex != -1 && m_leftIndex != -1)
                        {
                            if (m_rightIndex == m_leftIndex)
                            {
                                m_timeToEndAt        = System.DateTime.Now.AddSeconds(k_secondsToBuffer);
                                m_useGestureLocked   = true;
                                m_gestureLockMessage = strBuilder.ToString();
                                strBuilder.Append("\n" + gesture1_right[m_leftIndex].name);
                                Console.WriteLine(gesture1_right[m_leftIndex].name);
                                m_codeString     = m_codeString + gesture1_right[m_leftIndex].name + " ";
                                codeView.Content = m_codeString;
                                m_leftIndex      = -1;
                                m_rightIndex     = -1;
                                touchedRight     = false;
                                touchedLeft      = false;
                            }
                        }
                    }
                }

                //MessageBox.Show(strBuilder.ToString());

                //this is the place to draw sitting position or not
                skeletonDisplayManager.Draw(frame.Skeletons, false);
                Output.Text = strBuilder.ToString();
                //we only care about 1 skeleton
                break;
            }
        }
Example #15
0
        //public void initialstore(ReplaySkeletonFrame frame, int framenumber)


        public void storeframe(ReplaySkeletonFrame frame, int framenumber, CoordinateMapper replayCoordinateMapper)
        {
            //int framenumber;
            double leftShoulderAngle, leftHipAngle, leftKneeAngle, headHeight;
            double headX, headY, leftHandX, leftHandY, rightHandX, rightHandY;
            double leftshoulderX, leftshoulderY, rightshoulderX, rightshoulderY;
            double hipX, hipY, leftKneeX, leftKneeY, rightKneeX, rightKneeY;
            double leftFootX, leftFootY, rightFootX, rightFootY;

            //side view

            double headYabs, headZabs, leftHandYabs, leftHandZabs;
            double leftshoulderYabs, leftshoulderZabs, hipYabs, hipZabs;
            double leftKneeYabs, leftKneeZabs, leftFootYabs, leftFootZabs;



            if (isStartingFrame == true)
            {
                initialFrameNumber = framenumber;
                System.Console.WriteLine("initialFrame = " + initialFrameNumber);
                isStartingFrame = false;
            }

            if (frame == null)
            {
                //currentFrameNumber = framenumber - initialFrameNumber;
                leftShoulderAngle = 999;
                leftHipAngle      = 999;
                leftKneeAngle     = 999;
                headHeight        = 999;
                headX             = 999;
                headY             = 999;
                leftHandX         = 999;
                leftHandY         = 999;
                rightHandX        = 999;
                rightHandY        = 999;
                leftshoulderX     = 999;
                leftshoulderY     = 999;
                rightshoulderX    = 999;
                rightshoulderY    = 999;
                hipX       = 999;
                hipY       = 999;
                leftKneeX  = 999;
                leftKneeY  = 999;
                rightKneeX = 999;
                rightKneeY = 999;
                leftFootX  = 999;
                leftFootY  = 999;
                rightFootX = 999;
                rightFootY = 999;

                //side view
                headYabs         = 999;
                headZabs         = 999;
                leftHandYabs     = 999;
                leftHandZabs     = 999;
                leftshoulderYabs = 999;
                leftshoulderZabs = 999;
                hipYabs          = 999;
                hipZabs          = 999;
                leftKneeYabs     = 999;
                leftKneeZabs     = 999;
                leftFootYabs     = 999;
                leftFootZabs     = 999;


                //currentFrameNumber++;
            }

            else
            {
                var trackedSkeleton = frame.Skeletons.FirstOrDefault(a => a.TrackingState == SkeletonTrackingState.Tracked);
                //IMPORTATNT: 23 occurences frame here for deadlift1.replay
                if (trackedSkeleton == null)
                {
                    return;
                }

                //set starting frame of the video to index 1
                //framenumber = frame.FrameNumber - initialFrameNumber + 1;
                //currentFrameNumber = framenumber;
                leftShoulderAngle = JointAngle(trackedSkeleton.Joints[JointType.ShoulderLeft], trackedSkeleton.Joints[JointType.WristLeft], trackedSkeleton.Joints[JointType.HipLeft]);
                leftHipAngle      = JointAngle(trackedSkeleton.Joints[JointType.HipLeft], trackedSkeleton.Joints[JointType.ShoulderLeft], trackedSkeleton.Joints[JointType.KneeLeft]);
                leftKneeAngle     = JointAngle(trackedSkeleton.Joints[JointType.KneeLeft], trackedSkeleton.Joints[JointType.FootLeft], trackedSkeleton.Joints[JointType.HipLeft]);
                headHeight        = trackedSkeleton.Joints[JointType.Head].Position.Y;
                //frontal view
                headX          = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.Head].Position, ColorImageFormat.RgbResolution640x480Fps30).X;
                headY          = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.Head].Position, ColorImageFormat.RgbResolution640x480Fps30).Y;
                leftHandX      = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.HandLeft].Position, ColorImageFormat.RgbResolution640x480Fps30).X;
                leftHandY      = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.HandLeft].Position, ColorImageFormat.RgbResolution640x480Fps30).Y;
                rightHandX     = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.HandRight].Position, ColorImageFormat.RgbResolution640x480Fps30).X;
                rightHandY     = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.HandRight].Position, ColorImageFormat.RgbResolution640x480Fps30).Y;
                leftshoulderX  = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.ShoulderLeft].Position, ColorImageFormat.RgbResolution640x480Fps30).X;
                leftshoulderY  = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.ShoulderLeft].Position, ColorImageFormat.RgbResolution640x480Fps30).Y;
                rightshoulderX = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.ShoulderRight].Position, ColorImageFormat.RgbResolution640x480Fps30).X;
                rightshoulderY = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.ShoulderRight].Position, ColorImageFormat.RgbResolution640x480Fps30).Y;
                hipX           = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.HipCenter].Position, ColorImageFormat.RgbResolution640x480Fps30).X;
                hipY           = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.HipCenter].Position, ColorImageFormat.RgbResolution640x480Fps30).Y;
                leftKneeX      = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.KneeLeft].Position, ColorImageFormat.RgbResolution640x480Fps30).X;
                leftKneeY      = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.KneeLeft].Position, ColorImageFormat.RgbResolution640x480Fps30).Y;
                rightKneeX     = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.KneeRight].Position, ColorImageFormat.RgbResolution640x480Fps30).X;
                rightKneeY     = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.KneeRight].Position, ColorImageFormat.RgbResolution640x480Fps30).Y;
                leftFootX      = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.FootLeft].Position, ColorImageFormat.RgbResolution640x480Fps30).X;
                leftFootY      = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.FootLeft].Position, ColorImageFormat.RgbResolution640x480Fps30).Y;
                rightFootX     = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.FootRight].Position, ColorImageFormat.RgbResolution640x480Fps30).X;
                rightFootY     = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.FootRight].Position, ColorImageFormat.RgbResolution640x480Fps30).Y;


                //side view 22/03/2013
                headYabs         = trackedSkeleton.Joints[JointType.Head].Position.Y;
                headZabs         = trackedSkeleton.Joints[JointType.Head].Position.Z;
                leftHandYabs     = trackedSkeleton.Joints[JointType.HandLeft].Position.Y;
                leftHandZabs     = trackedSkeleton.Joints[JointType.HandLeft].Position.Z;
                leftshoulderYabs = trackedSkeleton.Joints[JointType.ShoulderLeft].Position.Y;
                leftshoulderZabs = trackedSkeleton.Joints[JointType.ShoulderLeft].Position.Z;
                hipYabs          = trackedSkeleton.Joints[JointType.HipCenter].Position.Y;
                hipZabs          = trackedSkeleton.Joints[JointType.HipCenter].Position.Z;
                leftKneeYabs     = trackedSkeleton.Joints[JointType.KneeLeft].Position.Y;
                leftKneeZabs     = trackedSkeleton.Joints[JointType.KneeLeft].Position.Z;
                leftFootYabs     = trackedSkeleton.Joints[JointType.FootLeft].Position.Y;
                leftFootZabs     = trackedSkeleton.Joints[JointType.FootLeft].Position.Z;
            }

            currentFrameNumber = framenumber - initialFrameNumber + 1;
            //System.Console.WriteLine("framenumber = " + framenumber);
            //System.Console.WriteLine("initialFrameNumber = " + initialFrameNumber);
            //System.Console.WriteLine("currentFrameNumber = " + currentFrameNumber);
            Framedata currentframe = new Framedata(currentFrameNumber, leftHipAngle, leftShoulderAngle, leftKneeAngle, headHeight, headX, headY, leftHandX, leftHandY, rightHandX, rightHandY, leftshoulderX, leftshoulderY, rightshoulderX, rightshoulderY, hipX, hipY, leftKneeX, leftKneeY, rightKneeX, rightKneeY, leftFootX, leftFootY, rightFootX, rightFootY, headYabs, headZabs, leftHandYabs, leftHandZabs, leftshoulderYabs, leftshoulderZabs, hipYabs, hipZabs, leftKneeYabs, leftKneeZabs, leftFootYabs, leftFootZabs);

            jointsdata.Add(currentframe);
        }