void Awake() { comparer = SkeletonComparer.GetComparer(CurveProvider.Curve); UserAvatar = UserRiggedAvatar as IAvatar ?? UserNativeAvatar; TechniqueAvatar = TechniqueRiggedAvatar as IAvatar ?? TechniqueNativeAvatar; }
public static double CompareActivities(ActivityRecord record, ActivityWindow window) { double result = 0; var mostInformativeJoints = record.MostInformativeJoints; List<ImportedSkeleton> windowPresentedByImportedSkeleton = new List<ImportedSkeleton>(); while(window.Frames.Count != 0) { windowPresentedByImportedSkeleton.Add(window.Frames.Dequeue()); } for (int i = 1; i < record.Frames.Count; i++) { for (int j = 0; j < windowPresentedByImportedSkeleton.Count; j++) { int index = (j / record.Frames.Count) * windowPresentedByImportedSkeleton.Count; if (index >= windowPresentedByImportedSkeleton.Count) index--; result += SkeletonComparer.CompareWithSMIJ(record.Frames[i], windowPresentedByImportedSkeleton[index], mostInformativeJoints); } } return result; }
public static double CompareActivities(ActivityRecord record, ActivityWindow window, DynamicTimeWarpingCalculationType dtwType, DynamicTimeWarpingPathTypes pathType = DynamicTimeWarpingPathTypes.Standart, bool toUseSakoeChibaBand = false, double bandWidthInProcentage = 0.1) { double similarity = 0.0f; double[,] DTW = new double[record.Frames.Count, window.Frames.Count]; for (int i = 1; i < window.Frames.Count; i++) { DTW[0, i] = double.PositiveInfinity; } for (int i = 1; i < record.Frames.Count; i++) { DTW[i, 0] = double.PositiveInfinity; } DTW[0, 0] = 0; var windowPresentedByImportedSkeletons = new List <ImportedSkeleton>(); foreach (var skeleton in window.Frames) { windowPresentedByImportedSkeletons.Add(new ImportedSkeleton(skeleton)); } int bandWidth = (int)(windowPresentedByImportedSkeletons.Count * bandWidthInProcentage); if (toUseSakoeChibaBand) { for (int i = 1; i < record.Frames.Count; i++) { for (int j = 1; j < windowPresentedByImportedSkeletons.Count; j++) { int currentCellOnMiddleDiagonal = (int)((j * windowPresentedByImportedSkeletons.Count) / record.Frames.Count); if (j > currentCellOnMiddleDiagonal - bandWidth && j < currentCellOnMiddleDiagonal + bandWidth) // Checking if the current cell is in the range { similarity = SkeletonComparer.CompareWithSMIJ(record.Frames[i], windowPresentedByImportedSkeletons[j], record.MostInformativeJoints); FillDTWTableCell(pathType, DTW, i, j, similarity); } } } } else //Start a DTW search without using Sakoe-Chiba band { for (int i = 1; i < record.Frames.Count; i++) { for (int j = 1; j < windowPresentedByImportedSkeletons.Count; j++) { similarity = SkeletonComparer.CompareWithSMIJ(record.Frames[i], windowPresentedByImportedSkeletons[j], record.MostInformativeJoints); FillDTWTableCell(pathType, DTW, i, j, similarity); } } } return(DTW[record.Frames.Count - 1, window.Frames.Count - 1] / record.MostInformativeJoints.Count); }
public void Init(Technique t) { technique = t; comparer = SkeletonComparer.GetComparer(CurveProvider.Curve); VariableHolder.RecordedSkeletonFrames = t.TechniqueFrames; PreviewPlayback.RefreshSkeletonFrames(); FinishedPlayback.RefreshSkeletonFrames(); PlaybackAvatar.SwapSkeletonProvider(PreviewPlayback); UserAvatar.SwapSkeletonProvider(CurrentUserTracker.Instance); PlaybackAvatar.SetEnabled(true); UserAvatar.SetEnabled(true); }
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); } } } }