/// <summary> /// 判断指定骨骼数据是否与指定姿势匹配 /// </summary> /// <param name="skeleton">骨骼数据</param> /// <param name="posture">姿势</param> /// <returns></returns> public static bool matches(Skeleton skeleton, Posture posture) { PostureType postureType = posture.Type; Posture pos = computePosture(skeleton, postureType); return(matches(pos, posture)); }
private void repaintIntervalGroup(ComboBox combo) { PostureType newPostureType = (PostureType)combo.SelectedItem; var visiblePosture = visiblePostures.Find(v => v.Item2 == combo); PostureType oldPostureType = visiblePosture.Item1; RowDefinition rowDef = visiblePosture.Item3; // CLEAR ROW OF INTERVAL GROUP int rowDefIndex = postureGroupsGrid.RowDefinitions.IndexOf(rowDef); //foreach (UIElement path in postureGroupsGrid.Children) for (int i = postureGroupsGrid.Children.Count - 1; i >= 0; i--) { if (Grid.GetRow(postureGroupsGrid.Children[i]) == rowDefIndex) { postureGroupsGrid.Children.RemoveAt(i); } } int visiblePostureIndex = visiblePostures.IndexOf(visiblePosture); visiblePostures.Remove(visiblePosture); visiblePostures.Insert(visiblePostureIndex, new Tuple <PostureType, ComboBox, RowDefinition> (newPostureType, combo, rowDef) ); PostureIntervalGroup postureIntervalGroup = Person.PostureIntervalGroups .FirstOrDefault (g => g.PostureType == newPostureType); if (postureIntervalGroup != null) { //StackPanel pathStackPanel = new StackPanel(); foreach (var interval in postureIntervalGroup.Intervals) { Console.WriteLine("\t[" + interval.StartTime.ToString(@"mm\:ss") + ", " + interval.EndTime.ToString(@"mm\:ss") + "]"); int intervalIniCol = Convert.ToInt32(interval.StartTime.TotalSeconds); int intervalFinCol = Convert.ToInt32(interval.EndTime.TotalSeconds); System.Windows.Shapes.Path path = new System.Windows.Shapes.Path(); path.Stroke = Person.Color;//System.Windows.Media.Brushes.Red; //person.Color; // postureIntervalGroup.postureType.color; // path.StrokeThickness = 10; path.Stretch = System.Windows.Media.Stretch.Fill; Grid.SetRow(path, rowDefIndex); int iniCol = (intervalIniCol - 1) >= 0 ? (intervalIniCol - 1) : 0; Grid.SetColumn(path, iniCol); Grid.SetColumnSpan(path, intervalFinCol - intervalIniCol + 2); System.Windows.Media.LineGeometry line = new System.Windows.Media.LineGeometry(); line.StartPoint = new System.Windows.Point(0d, 0d); line.EndPoint = new System.Windows.Point(1d, 0d); path.Data = line; //postureGroupsGrid. postureGroupsGrid.Children.Add(path); } } }
private void saveButton_Click(object sender, RoutedEventArgs e) { if (this.path == null) { MessageBox.Show("Debes ingresar un archivo"); } string name = nameTextBox.Text; if (PostureTypeContext.db.PostureType.Any(p => p.Name == name)) { if (editingPosture == null) { MessageBox.Show("La postura '" + name + "' ya existe. Utilize otro nombre."); } else if (editingPosture.Name != name) { MessageBox.Show("La postura '" + name + "' ya existe. Utilize otro nombre."); } else if (editingPosture.Name == name && editingPosture.Path == path) { this.Close(); } } else if (this.path != null && name != "") { Console.WriteLine("Saving posture: name: {0} --- path: {1}", name, this.path); string internalFilePath = @"Database\" + fileNameTextBox.Text; if (!File.Exists(internalFilePath)) { File.Copy(path, internalFilePath); } if (editingPosture != null) { PostureType postureToUpdate = PostureTypeContext.db.PostureType .FirstOrDefault(p => p.PostureTypeId == editingPosture.PostureTypeId); string oldPath = postureToUpdate.Path; postureToUpdate.Name = name; postureToUpdate.Path = internalFilePath; //SqliteAppContext.db.Entry(postureToUpdate).CurrentValues.SetValues(product); PostureTypeContext.db.SaveChanges(); if (!PostureTypeContext.db.PostureType.Any(p => p.Path == oldPath) && oldPath != internalFilePath) { File.Delete(oldPath); } } else { PostureTypeContext.db.PostureType.Add(new PostureType(name, internalFilePath)); } PostureTypeContext.db.SaveChanges(); MainWindow.postureCrud.refreshList(); this.Close(); } }
public AddOrEditPostureType(PostureType editingPosture) { InitializeComponent(); this.editingPosture = editingPosture; this.fileNameTextBox.Text = System.IO.Path.GetFileName(editingPosture.Path); this.nameTextBox.Text = editingPosture.Name; this.path = editingPosture.Path; }
private void editPostureButton_Click(object sender, RoutedEventArgs e) { PostureType selectedPosture = (PostureType)postureCrudDataGrid.SelectedItem; selectedPosture = PostureTypeContext.db.PostureType.FirstOrDefault(p => p.PostureTypeId == selectedPosture.PostureTypeId); AddOrEditPostureType addPostureView = new AddOrEditPostureType(selectedPosture); addPostureView.Show(); }
public Posture(PostureType type, double[][] vectors) { this.type = type; List <VectorType> types = PostureRecognition.getVectorTypeList(type); for (int i = 0; i < types.Count; i++) { setVector(types[i], new Vector(vectors[i][0], vectors[i][1], vectors[i][2])); } }
private void removePostureButton_Click(object sender, RoutedEventArgs e) { //int idx = postureCrudDataGrid.SelectedIndex; PostureType selectedItem = (PostureType)postureCrudDataGrid.SelectedItem; if (selectedItem != PostureType.none) { PostureTypeContext.db.PostureType.Remove(PostureTypeContext.db.PostureType.FirstOrDefault(p => p.PostureTypeId == selectedItem.PostureTypeId)); PostureTypeContext.db.SaveChanges(); this.refreshList(); } }
/// <summary> /// 获取制定姿势类型对应的向量类型list,采用静态变量,减少创建对象的次数 /// </summary> /// <param name="postureType">姿势类型(左臂、右臂、双臂)</param> /// <returns></returns> public static List <VectorType> getVectorTypeList(PostureType postureType) { if (postureType == PostureType.LeftArm) { return(leftArmVectorTypeList); } else if (postureType == PostureType.RightArm) { return(rightArmVectorTypeList); } else if (postureType == PostureType.Both) { return(bothArmVectorTypeList); } throw new Exception("postureType is illegal."); }
/// <summary> /// 计算指定骨骼在指定姿势类型下,对应的姿势 /// </summary> /// <param name="skeleton">骨骼数据</param> /// <param name="postureType">姿势类型(左臂、右臂、双臂)</param> /// <returns></returns> public static Posture computePosture(Skeleton skeleton, PostureType postureType) { Posture posture = new Posture(postureType); List <VectorType> vectorTypeList = getVectorTypeList(postureType); foreach (VectorType vectorType in vectorTypeList) { JointType jointType0, jointType1; switch (vectorType) { case VectorType.ShoulderElbowLeft: jointType0 = JointType.ShoulderLeft; jointType1 = JointType.ElbowLeft; break; case VectorType.ElbowWristLeft: jointType0 = JointType.ElbowLeft; jointType1 = JointType.WristLeft; break; case VectorType.ShoulderElbowRight: jointType0 = JointType.ShoulderRight; jointType1 = JointType.ElbowRight; break; case VectorType.ElbowWristRight: jointType0 = JointType.ElbowRight; jointType1 = JointType.WristRight; break; default: throw new Exception("vectorType is illegal."); } Joint joint0 = skeleton.Joints[jointType0]; Joint joint1 = skeleton.Joints[jointType1]; Vector vector = new Vector(joint1.Position.X - joint0.Position.X, joint1.Position.Y - joint0.Position.Y, joint1.Position.Z - joint0.Position.Z); posture.setVector(vectorType, vector); } return(posture); }
public PostureDetectedEventArgs(PostureType type, int percentage, long timestamp) { this.m_type = type; this.m_percentage = percentage; this.m_timestamp = timestamp; }
public Posture(PostureType type, double[][] vectors, String picPath) : this(type, vectors) { setPic(picPath); }
public Posture(PostureType type) { this.type = type; }
/// <summary> /// Enable the recognition of a specific posture /// </summary> /// <param name="postureType">The type of posture to enable</param> public void EnablePostureRecognition(PostureType postureType) { switch (postureType) { // we subscribe to the corresponding events from the scheduler case PostureType.Rock: ParametersOther.Instance.RockEnable = true; m_Scheduler.EnablePostureRecognition(PostureType.Rock); m_Scheduler.RockPostureSucceed += OnRockPostureSucceed; m_Scheduler.RockPostureDetectionInProgress += OnRockPostureDetectionInProgress; m_Scheduler.RockPostureDetectionLost += OnRockPostureDetectionLost; break; case PostureType.Paper: ParametersOther.Instance.PaperEnable = true; m_Scheduler.EnablePostureRecognition(PostureType.Paper); m_Scheduler.PaperPostureSucceed += OnPaperPostureSucceed; m_Scheduler.PaperPostureDetectionInProgress += OnPaperPostureDetectionInProgress; m_Scheduler.PaperPostureDetectionLost += OnPaperPostureDetectionLost; break; case PostureType.Scissors: ParametersOther.Instance.ScissorsEnable = true; m_Scheduler.EnablePostureRecognition(PostureType.Scissors); m_Scheduler.ScissorsPostureSucceed += OnScissorsPostureSucceed; m_Scheduler.ScissorsPostureDetectionInProgress += OnScissorsPostureDetectionInProgress; m_Scheduler.ScissorsPostureDetectionLost += OnScissorsPostureDetectionLost; break; case PostureType.Zero: ParametersOther.Instance.ZeroEnable = true; m_Scheduler.EnablePostureRecognition(PostureType.Zero); m_Scheduler.ZeroFingerPostureSucceed += OnZeroFingerPostureSucceed; m_Scheduler.ZeroFingerPostureDetectionInProgress += OnZeroFingerPostureDetectionInProgress; m_Scheduler.ZeroFingerPostureDetectionLost += OnZeroFingerPostureDetectionLost; break; case PostureType.One: ParametersOther.Instance.OneEnable = true; m_Scheduler.EnablePostureRecognition(PostureType.One); m_Scheduler.OneFingerPostureSucceed += OnOneFingerPostureSucceed; m_Scheduler.OneFingerPostureDetectionInProgress += OnOneFingerPostureDetectionInProgress; m_Scheduler.OneFingerPostureDetectionLost += OnOneFingerPostureDetectionLost; break; case PostureType.Two: ParametersOther.Instance.TwoEnable = true; m_Scheduler.EnablePostureRecognition(PostureType.Two); m_Scheduler.TwoFingersPostureSucceed += OnTwoFingersPostureSucceed; m_Scheduler.TwoFingersPostureDetectionInProgress += OnTwoFingersPostureDetectionInProgress; m_Scheduler.TwoFingersPostureDetectionLost += OnTwoFingersPostureDetectionLost; break; case PostureType.Three: ParametersOther.Instance.ThreeEnable = true; m_Scheduler.EnablePostureRecognition(PostureType.Three); m_Scheduler.ThreeFingersPostureSucceed += OnThreeFingersPostureSucceed; m_Scheduler.ThreeFingersPostureDetectionInProgress += OnThreeFingersPostureDetectionInProgress; m_Scheduler.ThreeFingersPostureDetectionLost += OnThreeFingersPostureDetectionLost; break; case PostureType.Four: ParametersOther.Instance.FourEnable = true; m_Scheduler.EnablePostureRecognition(PostureType.Four); m_Scheduler.FourFingersPostureSucceed += OnFourFingersPostureSucceed; m_Scheduler.FourFingersPostureDetectionInProgress += OnFourFingersPostureDetectionInProgress; m_Scheduler.FourFingersPostureDetectionLost += OnFourFingersPostureDetectionLost; break; case PostureType.Five: ParametersOther.Instance.FiveEnable = true; m_Scheduler.EnablePostureRecognition(PostureType.Five); m_Scheduler.FiveFingersPostureSucceed += OnFiveFingersPostureSucceed; m_Scheduler.FiveFingersPostureDetectionInProgress += OnFiveFingersPostureDetectionInProgress; m_Scheduler.FiveFingersPostureDetectionLost += OnFiveFingersPostureDetectionLost; break; default: break; } }
// This function raise an event is a posture is held, restart the postureEndTimer and fill the last posture timestamp private void RaisePostureHeld(PostureType postureType, long timestamp) { switch (postureType) { case PostureType.Rock: if (PostureRockHeld != null) { RestartTimer(this.m_PostureEndTimer); PostureRockHeld(this, new PostureDetectedEventArgs(postureType, timestamp)); this.m_lastPostureTimestamp = new Tuple<PostureType, long>(postureType, timestamp); } break; case PostureType.Scissors: if (PostureScissorsHeld != null) { RestartTimer(this.m_PostureEndTimer); PostureScissorsHeld(this, new PostureDetectedEventArgs(postureType, timestamp)); this.m_lastPostureTimestamp = new Tuple<PostureType, long>(postureType, timestamp); } break; case PostureType.Paper: if (PosturePaperHeld != null) { RestartTimer(this.m_PostureEndTimer); PosturePaperHeld(this, new PostureDetectedEventArgs(postureType, timestamp)); this.m_lastPostureTimestamp = new Tuple<PostureType, long>(postureType, timestamp); } break; case PostureType.Zero: if (PostureZeroHeld != null) { RestartTimer(this.m_PostureEndTimer); PostureZeroHeld(this, new PostureDetectedEventArgs(postureType, timestamp)); this.m_lastPostureTimestamp = new Tuple<PostureType, long>(postureType, timestamp); } break; case PostureType.One: if (PostureOneHeld != null) { RestartTimer(this.m_PostureEndTimer); PostureOneHeld(this, new PostureDetectedEventArgs(postureType, timestamp)); this.m_lastPostureTimestamp = new Tuple<PostureType, long>(postureType, timestamp); } break; case PostureType.Two: if (PostureTwoHeld != null) { RestartTimer(this.m_PostureEndTimer); PostureTwoHeld(this, new PostureDetectedEventArgs(postureType, timestamp)); this.m_lastPostureTimestamp = new Tuple<PostureType, long>(postureType, timestamp); } break; case PostureType.Three: if (PostureThreeHeld != null) { RestartTimer(this.m_PostureEndTimer); PostureThreeHeld(this, new PostureDetectedEventArgs(postureType, timestamp)); this.m_lastPostureTimestamp = new Tuple<PostureType, long>(postureType, timestamp); } break; case PostureType.Four: if (PostureFourHeld != null) { RestartTimer(this.m_PostureEndTimer); PostureFourHeld(this, new PostureDetectedEventArgs(postureType, timestamp)); this.m_lastPostureTimestamp = new Tuple<PostureType, long>(postureType, timestamp); } break; case PostureType.Five: if (PostureFiveHeld != null) { RestartTimer(this.m_PostureEndTimer); PostureFiveHeld(this, new PostureDetectedEventArgs(postureType, timestamp)); this.m_lastPostureTimestamp = new Tuple<PostureType, long>(postureType, timestamp); } break; default: break; } }
// This function raise an event if the posture just begin to be detected. // It also set the flag to true, fill the last posture timestamp and start the postureEndTimer. // If this timer elapsed, it means that a posture is no more recognize (too much time elapsed since the last raise of event) so that the posture ends. private void RaisePostureBegin(PostureType postureType, long timestamp) { switch (postureType) { case PostureType.Rock: if (PostureRockBegin != null) { this.m_FlagPosture[postureType] = true; this.m_PostureEndTimer.Start(); PostureRockBegin(this, new PostureDetectedEventArgs(postureType, timestamp)); this.m_lastPostureTimestamp = new Tuple<PostureType, long>(postureType, timestamp); } break; case PostureType.Scissors: if (PostureScissorsBegin != null) { this.m_FlagPosture[postureType] = true; this.m_PostureEndTimer.Start(); PostureScissorsBegin(this, new PostureDetectedEventArgs(postureType, timestamp)); this.m_lastPostureTimestamp = new Tuple<PostureType, long>(postureType, timestamp); } break; case PostureType.Paper: if (PosturePaperBegin != null) { this.m_FlagPosture[postureType] = true; this.m_PostureEndTimer.Start(); PosturePaperBegin(this, new PostureDetectedEventArgs(postureType, timestamp)); this.m_lastPostureTimestamp = new Tuple<PostureType, long>(postureType, timestamp); } break; case PostureType.Zero: if (PostureZeroBegin != null) { this.m_FlagPosture[postureType] = true; this.m_PostureEndTimer.Start(); PostureZeroBegin(this, new PostureDetectedEventArgs(postureType, timestamp)); this.m_lastPostureTimestamp = new Tuple<PostureType, long>(postureType, timestamp); } break; case PostureType.One: if (PostureOneBegin != null) { this.m_FlagPosture[postureType] = true; this.m_PostureEndTimer.Start(); PostureOneBegin(this, new PostureDetectedEventArgs(postureType, timestamp)); this.m_lastPostureTimestamp = new Tuple<PostureType, long>(postureType, timestamp); } break; case PostureType.Two: if (PostureTwoBegin != null) { this.m_FlagPosture[postureType] = true; this.m_PostureEndTimer.Start(); PostureTwoBegin(this, new PostureDetectedEventArgs(postureType, timestamp)); this.m_lastPostureTimestamp = new Tuple<PostureType, long>(postureType, timestamp); } break; case PostureType.Three: if (PostureThreeBegin != null) { this.m_FlagPosture[postureType] = true; this.m_PostureEndTimer.Start(); PostureThreeBegin(this, new PostureDetectedEventArgs(postureType, timestamp)); this.m_lastPostureTimestamp = new Tuple<PostureType, long>(postureType, timestamp); } break; case PostureType.Four: if (PostureFourBegin != null) { this.m_FlagPosture[postureType] = true; this.m_PostureEndTimer.Start(); PostureFourBegin(this, new PostureDetectedEventArgs(postureType, timestamp)); this.m_lastPostureTimestamp = new Tuple<PostureType, long>(postureType, timestamp); } break; case PostureType.Five: if (PostureFiveBegin != null) { this.m_FlagPosture[postureType] = true; this.m_PostureEndTimer.Start(); PostureFiveBegin(this, new PostureDetectedEventArgs(postureType, timestamp)); this.m_lastPostureTimestamp = new Tuple<PostureType, long>(postureType, timestamp); } break; default: break; } }
/// <summary> /// Enable the recognition of a specific posture /// </summary> /// <param name="postureType">The type of posture to enable</param> internal void EnablePostureRecognition(PostureType postureType) { switch (postureType) { // we subscribe to the corresponding events from the posture recognizer case PostureType.Rock: m_PostureRecognizer.PostureRockBegin += OnPostureRockBegin; m_PostureRecognizer.PostureRockHeld += OnPostureRockHeld; break; case PostureType.Scissors: m_PostureRecognizer.PostureScissorsBegin += OnPostureScissorsBegin; m_PostureRecognizer.PostureScissorsHeld += OnPostureScissorsHeld; break; case PostureType.Paper: m_PostureRecognizer.PosturePaperBegin += OnPosturePaperBegin; m_PostureRecognizer.PosturePaperHeld += OnPosturePaperHeld; break; case PostureType.Zero: m_PostureRecognizer.PostureZeroBegin += OnPostureZeroBegin; m_PostureRecognizer.PostureZeroHeld += OnPostureZeroHeld; break; case PostureType.One: m_PostureRecognizer.PostureOneBegin += OnPostureOneBegin; m_PostureRecognizer.PostureOneHeld += OnPostureOneHeld; break; case PostureType.Two: m_PostureRecognizer.PostureTwoBegin += OnPostureTwoBegin; m_PostureRecognizer.PostureTwoHeld += OnPostureTwoHeld; break; case PostureType.Three: m_PostureRecognizer.PostureThreeBegin += OnPostureThreeBegin; m_PostureRecognizer.PostureThreeHeld += OnPostureThreeHeld; break; case PostureType.Four: m_PostureRecognizer.PostureFourBegin += OnPostureFourBegin; m_PostureRecognizer.PostureFourHeld += OnPostureFourHeld; break; case PostureType.Five: m_PostureRecognizer.PostureFiveBegin += OnPostureFiveBegin; m_PostureRecognizer.PostureFiveHeld += OnPostureFiveHeld; break; } }