From f8199a2e1f3f0677287aa1edb7b8b9f1e77d9adb Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 15 May 2012 19:27:48 +1000 Subject: [PATCH] hmm implemented --- .../Gesture Recognition/GestureRecognizer.cs | 8 +++--- .../Gesture Recognition/HMMRecognizer.cs | 6 ++--- .../Assets/Other/Scripts/WiiReader.cs | 23 ++++++++++-------- .../Assets/player/prefabs/player.prefab | Bin 30360 -> 31568 bytes .../Assets/player/scripts/playerAttack.cs | 16 ++++++------ 5 files changed, 27 insertions(+), 26 deletions(-) diff --git a/unity_project/Assets/Gesture Recognition/GestureRecognizer.cs b/unity_project/Assets/Gesture Recognition/GestureRecognizer.cs index ada766f..cf90da6 100644 --- a/unity_project/Assets/Gesture Recognition/GestureRecognizer.cs +++ b/unity_project/Assets/Gesture Recognition/GestureRecognizer.cs @@ -171,7 +171,7 @@ public class GestureRecognizer { } public class WiiGestures { - public Vector2[] GetGestureFromPoints(Vector2[] points) { + public Gesture GetGestureFromPoints(Vector2[] points) { var list = new List(); for (int i = 1; i < points.Length; ++i) { @@ -191,7 +191,7 @@ public class WiiGestures { // foreach(Vector2 v in list) // Debug.Log(v.ToString()); - return list.ToArray(); + return new Gesture(list.ToArray()); } private List FilterAccelerations(List accelerations) { @@ -205,7 +205,7 @@ public class WiiGestures { } private List FilterAccelerationsByDirection(List accelerations) { - float angleThresholdDegrees = 15.0f; + float angleThresholdDegrees = 5.0f; List list; if (accelerations.Count < 2) { @@ -220,7 +220,7 @@ public class WiiGestures { Vector2 b = accelerations[i]; float angle = Vector2.Angle(a, b); - Debug.Log(Mathf.Abs(angle).ToString()); +// Debug.Log(Mathf.Abs(angle).ToString()); if (Mathf.Abs(angle) > angleThresholdDegrees) { list.Add(b); } diff --git a/unity_project/Assets/Gesture Recognition/HMMRecognizer.cs b/unity_project/Assets/Gesture Recognition/HMMRecognizer.cs index f5762c0..3037ad1 100644 --- a/unity_project/Assets/Gesture Recognition/HMMRecognizer.cs +++ b/unity_project/Assets/Gesture Recognition/HMMRecognizer.cs @@ -23,9 +23,7 @@ public class HMMRecognizer : MonoBehaviour public const int SOUTH_EAST = 6; public const int SOUTH_WEST = 7; - void Start(){ - Debug.Log("Final Result: " + hmmEvalute(new int[]{NORTH, EAST, SOUTH, WEST}) + "\n"); - } + bool squareEvalution(int [] input){ if(input.Length != 4){ @@ -209,7 +207,7 @@ public class HMMRecognizer : MonoBehaviour double [] pi = new double [] {0.5, 0.5, 0, 0, 0, 0, 0, 0}; HiddenMarkovModel model = new HiddenMarkovModel(A, B, pi); - model.Learn(sequences, 0.0001); + model.Learn(sequences, 0.0001); if(model.Evaluate(input) >= 0.5){ return true; diff --git a/unity_project/Assets/Other/Scripts/WiiReader.cs b/unity_project/Assets/Other/Scripts/WiiReader.cs index 1730501..c5e7706 100644 --- a/unity_project/Assets/Other/Scripts/WiiReader.cs +++ b/unity_project/Assets/Other/Scripts/WiiReader.cs @@ -79,16 +79,19 @@ public class WiiReader : MonoBehaviour { }else if(recording[i]){ recording[i] = false; -// var recognizer = GestureRecognizer.GetSharedInstance(); -// var wiiGestures = new WiiGestures(); -// var geture = wiiGestures.GetGestureFromPoints(points[i].ToArray()); -// try { -// var gesture = recognizer.RecognizeGesture(geture); -// Debug.Log(string.Format("Recognized gesture: {0}", gesture)); -// } -// catch (UnityException e) { -// Debug.Log(e); -// } + var recognizer = gameObject.AddComponent(); + var wiiGestures = new WiiGestures(); + var gesture = wiiGestures.GetGestureFromPoints(points[i].ToArray()); + + foreach(int g in gesture.HmmDirections) + Debug.Log(g); + try { + var hmm = recognizer.hmmEvalute(gesture.HmmDirections); + Debug.Log(string.Format("Recognized gesture: {0}", hmm)); + } + catch (UnityException e) { + Debug.Log(e); + } } } } diff --git a/unity_project/Assets/player/prefabs/player.prefab b/unity_project/Assets/player/prefabs/player.prefab index 60be5285a241eddd1d655a42a8cb7eb46b77e558..e6afb33990c10aee7b4a5a14ee5aed72f43d2cb7 100644 GIT binary patch delta 1143 zcmZY8Ur1AN6bJ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fca..ffa17b0 100644 --- a/unity_project/Assets/player/scripts/playerAttack.cs +++ b/unity_project/Assets/player/scripts/playerAttack.cs @@ -51,16 +51,16 @@ public class playerAttack : MonoBehaviour { } if(gameObject.name == "player2"){ - if(currentEvent != null && currentEvent.type == EventType.MouseUp) { - var recognizer = GestureRecognizer.GetSharedInstance(); + if(currentEvent != null && currentEvent.type == EventType.MouseUp) { + var recognizer = gameObject.AddComponent(); var mouseGestures = new MouseGestures(); - var geture = mouseGestures.GetGestureFromPoints(points); + var gesture = mouseGestures.GetGestureFromPoints(points); + + foreach(int g in gesture.HmmDirections) + Debug.Log(g); try { - var gesture = recognizer.RecognizeGesture(geture); - Debug.Log(string.Format("Recognized gesture: {0}", gesture)); - -// createSpell(gesture.Name); - + var hmm = recognizer.hmmEvalute(gesture.HmmDirections); + Debug.Log(string.Format("Recognized gesture: {0}", hmm)); } catch (UnityException e) { Debug.Log(e);