示例#1
0
        public void AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            currentFrame++;

            using (DepthImageFrame depth = e.OpenDepthImageFrame())
            {
                #region Regular checks
                #region First
                if (kinectSensor == null)
                {
                    return;
                }
                GC.Collect();
                #endregion

                Skeleton first = Utility.GetFirstSkeleton.Get(e, allSkeletons);

                #region Second
                if (first == null)
                {
                    return;
                }
                #endregion
                #endregion

                if (CurrentMode == Mode.FillingWindow)
                {
                    window.Add(new ImportedSkeleton(first), ACCEPTABLE_WINDOW_SIZE);

                    if (window.Size >= ACCEPTABLE_WINDOW_SIZE)
                    {
                        CurrentMode = Mode.AlgorithmRunning;
                    }
                }

                if (CurrentMode == Mode.AlgorithmRunning)
                {
                    if (currentFrame % 2 == 0)
                    {
                        foreach (var activity in Activities)
                        {
                            double overallResult = 0.0;
                            foreach (var activityRecord in activity.Recordings)
                            {
                                var activityRecordResult = 0.0;
                                if (AlgorithmType == AlgorithmTypes.DTW)
                                {
                                    activityRecordResult = DTW(activityRecord, window, DynamicTimeWarpingCalculationType.Standart, StepPattern, true);
                                }

                                else if (AlgorithmType == AlgorithmTypes.DLM)
                                {
                                    activityRecordResult = ElasticMatchingWithFreedomDegree.CompareActivities(activityRecord, window);
                                }

                                overallResult += activityRecordResult;
                            }

                            overallResult /= activity.Recordings.Count;

                            var currentAlgorithmAcceptableActionSimilarity = 0;

                            if (AlgorithmType == AlgorithmTypes.DTW)
                            {
                                currentAlgorithmAcceptableActionSimilarity = AcceptableActionSimilarity.DTW;
                            }

                            else if (AlgorithmType == AlgorithmTypes.DLM)
                            {
                                currentAlgorithmAcceptableActionSimilarity = AcceptableActionSimilarity.DLM;
                            }

                            if (overallResult <= currentAlgorithmAcceptableActionSimilarity && !activityRecognizingStartedTriggered)
                            {
                                activityRecognizingStartedTriggered = true;
                                activityRecognizingEndedTriggered   = false;
                                ActivityRecognizingStarted.Invoke(this, new ActivityRecognizingEventArgs(activity, overallResult));
                                recognizedActivityName = activity.Name;
                            }
                            else if (overallResult > currentAlgorithmAcceptableActionSimilarity && !activityRecognizingEndedTriggered && recognizedActivityName == activity.Name)
                            {
                                activityRecognizingEndedTriggered   = true;
                                activityRecognizingStartedTriggered = false;
                                ActivityRecognizingEnded.Invoke(this, new ActivityRecognizingEventArgs(activity, overallResult));
                            }
                            Console.WriteLine(overallResult);
                        }
                        Console.WriteLine();
                    }
                    CurrentMode = Mode.FillingWindow;
                }

                if (CurrentMode == Mode.ToSelectMainSkeleton)
                {
                    CurrentMode = Mode.None;

                    mainSkeleton = first;

                    JointAnglesManager jointManager = new JointAnglesManager(first);
                    mainSkeletonWithAngles = jointManager.GetComputedAngles(mainSkeleton);
                }

                if (CurrentMode == Mode.ComparingSkeletons)
                {
                    ///Debug data - Most informative joints
                    List <JointType> joints = new List <JointType>();
                    joints.Add(JointType.ShoulderLeft);
                    joints.Add(JointType.ShoulderRight);
                    joints.Add(JointType.Head);
                    joints.Add(JointType.ElbowLeft);
                    joints.Add(JointType.ElbowRight);

                    ///

                    Skeleton secondarySkeleton = first;

                    var jointManager = new JointAnglesManager(secondarySkeleton);
                    var secondarySkeletonWithAngles = jointManager.GetComputedAngles(secondarySkeleton);

                    var result = SkeletonComparer.CompareWithSMIJ(mainSkeletonWithAngles, secondarySkeletonWithAngles, joints);

                    Console.WriteLine("Skeleton comparison: {0}", result);

                    if (result < ACCEPTABLE_SKELETON_SIMILARITY)
                    {
                        PoseRecognizedEventArgs args = new PoseRecognizedEventArgs(result);
                        PoseReconized.Invoke(this, args);
                    }
                }
            }
        }
        public void AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            currentFrame++;

            using (DepthImageFrame depth = e.OpenDepthImageFrame())
            {
                #region Regular checks
                #region First
                if (kinectSensor == null)
                {
                    return;
                }
                GC.Collect();
                #endregion

                Skeleton first = Utility.GetFirstSkeleton.Get(e, allSkeletons);

                #region Second
                if (first == null)
                {
                    return;
                }
                #endregion
                #endregion

                if (CurrentMode == Mode.FillingWindow)
                {
                    window.Add(new ImportedSkeleton(first), ACCEPTABLE_WINDOW_SIZE);

                    if (window.Size >= ACCEPTABLE_WINDOW_SIZE)
                    {
                        CurrentMode = Mode.AlgorithmRunning;
                    }
                }

                if (CurrentMode == Mode.AlgorithmRunning)
                {
                    if (currentFrame % 2 == 0)
                    {
                        foreach (var activity in Activities)
                        {
                            double overallResult = 0.0;
                            foreach (var activityRecord in activity.Recordings)
                            {
                                var activityRecordResult = 0.0;
                                if (AlgorithmType == AlgorithmTypes.DTW)
                                {
                                    activityRecordResult = DTW(activityRecord, window, DynamicTimeWarpingCalculationType.Standart, StepPattern, true);
                                }

                                else if (AlgorithmType == AlgorithmTypes.DLM)
                                {
                                    activityRecordResult = ElasticMatchingWithFreedomDegree.CompareActivities(activityRecord, window);
                                }

                                overallResult += activityRecordResult;
                            }

                            overallResult /= activity.Recordings.Count;

                            var currentAlgorithmAcceptableActionSimilarity = 0;

                            if (AlgorithmType == AlgorithmTypes.DTW)
                            {
                                currentAlgorithmAcceptableActionSimilarity = AcceptableActionSimilarity.DTW;
                            }

                            else if(AlgorithmType == AlgorithmTypes.DLM){
                                currentAlgorithmAcceptableActionSimilarity = AcceptableActionSimilarity.DLM;
                            }

                            if (overallResult <= currentAlgorithmAcceptableActionSimilarity && !activityRecognizingStartedTriggered)
                            {
                                activityRecognizingStartedTriggered = true;
                                activityRecognizingEndedTriggered = false;
                                ActivityRecognizingStarted.Invoke(this, new ActivityRecognizingEventArgs(activity, overallResult));
                                recognizedActivityName = activity.Name;
                            }
                            else if (overallResult > currentAlgorithmAcceptableActionSimilarity && !activityRecognizingEndedTriggered && recognizedActivityName == activity.Name)
                            {
                                activityRecognizingEndedTriggered = true;
                                activityRecognizingStartedTriggered = false;
                                ActivityRecognizingEnded.Invoke(this, new ActivityRecognizingEventArgs(activity, overallResult));
                            }
                            Console.WriteLine(overallResult);
                        }
                        Console.WriteLine();
                    }
                    CurrentMode = Mode.FillingWindow;
                }

                if (CurrentMode == Mode.ToSelectMainSkeleton)
                {
                    CurrentMode = Mode.None;

                    mainSkeleton = first;

                    JointAnglesManager jointManager = new JointAnglesManager(first);
                    mainSkeletonWithAngles = jointManager.GetComputedAngles(mainSkeleton);
                }

                if (CurrentMode == Mode.ComparingSkeletons)
                {

                    ///Debug data - Most informative joints
                    List<JointType> joints = new List<JointType>();
                    joints.Add(JointType.ShoulderLeft);
                    joints.Add(JointType.ShoulderRight);
                    joints.Add(JointType.Head);
                    joints.Add(JointType.ElbowLeft);
                    joints.Add(JointType.ElbowRight);

                    ///

                    Skeleton secondarySkeleton = first;

                    var jointManager = new JointAnglesManager(secondarySkeleton);
                    var secondarySkeletonWithAngles = jointManager.GetComputedAngles(secondarySkeleton);

                    var result = SkeletonComparer.CompareWithSMIJ(mainSkeletonWithAngles, secondarySkeletonWithAngles, joints);

                    Console.WriteLine("Skeleton comparison: {0}", result);

                    if (result < ACCEPTABLE_SKELETON_SIMILARITY)
                    {
                        PoseRecognizedEventArgs args = new PoseRecognizedEventArgs(result);
                        PoseReconized.Invoke(this, args);
                    }
                }
            }
        }
 void recognitionCore_PoseReconized(object sender, PoseRecognizedEventArgs e)
 {
     poseRecognitionResult = e.Result;
     toDrawSuccessText = true;
 }