Esempio n. 1
0
 public ImportedSkeleton(ImportedSkeleton skeleton)
     : base()
 {
     InitializeDictionaries();
     CopyBasicDataFromSkeleton(skeleton);
     CopyBoneOrientationsFromImportedSkeleton(skeleton);
 }
 public ImportedSkeleton(ImportedSkeleton skeleton)
     : base()
 {
     InitializeDictionaries();
     CopyBasicDataFromSkeleton(skeleton);
     CopyBoneOrientationsFromImportedSkeleton(skeleton);
 }
Esempio n. 3
0
        private void CopyBoneOrientationsFromImportedSkeleton(ImportedSkeleton skeleton)
        {
            foreach (var key in Enum.GetNames(typeof(JointType)))
            {
                var joint = (JointType)Enum.Parse(typeof(JointType), key);
                this.Joints[joint] = skeleton.Joints[joint];

                this.HiararchicalQuaternions[joint].X = skeleton.HiararchicalQuaternions[joint].X;
                this.HiararchicalQuaternions[joint].Y = skeleton.HiararchicalQuaternions[joint].Y;
                this.HiararchicalQuaternions[joint].Z = skeleton.HiararchicalQuaternions[joint].Z;
                this.HiararchicalQuaternions[joint].W = skeleton.HiararchicalQuaternions[joint].W;

                this.AbsoluteQuaternions[joint].X = skeleton.AbsoluteQuaternions[joint].X;
                this.AbsoluteQuaternions[joint].Y = skeleton.AbsoluteQuaternions[joint].Y;
                this.AbsoluteQuaternions[joint].Z = skeleton.AbsoluteQuaternions[joint].Z;
                this.AbsoluteQuaternions[joint].W = skeleton.AbsoluteQuaternions[joint].W;
            }
        }
        private void CopyBoneOrientationsFromImportedSkeleton(ImportedSkeleton skeleton)
        {
            foreach (var key in Enum.GetNames(typeof(JointType)))
            {
                var joint = (JointType)Enum.Parse(typeof(JointType), key);
                this.Joints[joint] = skeleton.Joints[joint];

                this.HiararchicalQuaternions[joint].X = skeleton.HiararchicalQuaternions[joint].X;
                this.HiararchicalQuaternions[joint].Y = skeleton.HiararchicalQuaternions[joint].Y;
                this.HiararchicalQuaternions[joint].Z = skeleton.HiararchicalQuaternions[joint].Z;
                this.HiararchicalQuaternions[joint].W = skeleton.HiararchicalQuaternions[joint].W;

                this.AbsoluteQuaternions[joint].X = skeleton.AbsoluteQuaternions[joint].X;
                this.AbsoluteQuaternions[joint].Y = skeleton.AbsoluteQuaternions[joint].Y;
                this.AbsoluteQuaternions[joint].Z = skeleton.AbsoluteQuaternions[joint].Z;
                this.AbsoluteQuaternions[joint].W = skeleton.AbsoluteQuaternions[joint].W;
            }
        }
        public static double CompareWithSMIJ(ImportedSkeleton mainSkeleton, ImportedSkeleton secondarySkeleton, List<JointType> mostInformativeJoints)
        {
            double overall = 0;

            int jointID = 0;
            foreach (var joint in mostInformativeJoints)
            {
                var jointWeight = (mostInformativeJoints.Count - jointID) == 0 ? 1 : (mostInformativeJoints.Count - jointID);

                var similarity = CompareQuaternions(mainSkeleton.HiararchicalQuaternions[joint],
                        secondarySkeleton.HiararchicalQuaternions[joint]);

                overall += (similarity * 1000);// * jointWeight;

                jointID++;
            }

            return overall;
        }
Esempio n. 6
0
        public static double CompareWithSMIJ(ImportedSkeleton mainSkeleton, ImportedSkeleton secondarySkeleton, List <JointType> mostInformativeJoints)
        {
            double overall = 0;

            int jointID = 0;

            foreach (var joint in mostInformativeJoints)
            {
                var jointWeight = (mostInformativeJoints.Count - jointID) == 0 ? 1 : (mostInformativeJoints.Count - jointID);

                var similarity = CompareQuaternions(mainSkeleton.HiararchicalQuaternions[joint],
                                                    secondarySkeleton.HiararchicalQuaternions[joint]);

                overall += (similarity * 1000);                // * jointWeight;

                jointID++;
            }

            return(overall);
        }
        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 Add(ImportedSkeleton skel, int maxSize)
 {
     windowFixedSize = maxSize;
     Frames.Enqueue(skel);
     FixFramesLenght();
 }
        private static ImportedSkeleton CalculateSkeletonDerivative(List<ImportedSkeleton> query, int index, List<JointType> mostInformativeJoints)
        {
            var skeletonToReturn = new ImportedSkeleton();
            if (index < query.Count - 1)
            {
                foreach (var jointType in mostInformativeJoints)
                {

                    var currentMinusPrev = new JointRotation(
                        query[index].HiararchicalQuaternions[jointType].X - query[index - 1].HiararchicalQuaternions[jointType].X,
                        query[index].HiararchicalQuaternions[jointType].Y - query[index - 1].HiararchicalQuaternions[jointType].Y,
                        query[index].HiararchicalQuaternions[jointType].Z - query[index - 1].HiararchicalQuaternions[jointType].Z,
                        query[index].HiararchicalQuaternions[jointType].W - query[index - 1].HiararchicalQuaternions[jointType].W);

                    var nextMinusPrevDividedByTwo = new JointRotation(
                        (query[index + 1].HiararchicalQuaternions[jointType].X - query[index - 1].HiararchicalQuaternions[jointType].X) / 2,
                        (query[index + 1].HiararchicalQuaternions[jointType].Y - query[index - 1].HiararchicalQuaternions[jointType].Y) / 2,
                        (query[index + 1].HiararchicalQuaternions[jointType].Z - query[index - 1].HiararchicalQuaternions[jointType].Z) / 2,
                        (query[index + 1].HiararchicalQuaternions[jointType].W - query[index - 1].HiararchicalQuaternions[jointType].W) / 2);

                    var calculatedDerivative = new JointRotation(
                        (currentMinusPrev.X + nextMinusPrevDividedByTwo.X) / 2,
                        (currentMinusPrev.Y + nextMinusPrevDividedByTwo.Y) / 2,
                        (currentMinusPrev.Z + nextMinusPrevDividedByTwo.Z) / 2,
                        (currentMinusPrev.W + nextMinusPrevDividedByTwo.W) / 2
                        );

                    skeletonToReturn.HiararchicalQuaternions[jointType] = calculatedDerivative;

                }
            }
            return skeletonToReturn;
        }