Permalink
Browse files

hmm implemented

  • Loading branch information...
1 parent bb50912 commit f8199a2e1f3f0677287aa1edb7b8b9f1e77d9adb unknown committed May 15, 2012
@@ -171,7 +171,7 @@ public class GestureRecognizer {
}
public class WiiGestures {
- public Vector2[] GetGestureFromPoints(Vector2[] points) {
+ public Gesture GetGestureFromPoints(Vector2[] points) {
var list = new List<Vector2>();
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<Vector2> FilterAccelerations(List<Vector2> accelerations) {
@@ -205,7 +205,7 @@ public class WiiGestures {
}
private List<Vector2> FilterAccelerationsByDirection(List<Vector2> accelerations) {
- float angleThresholdDegrees = 15.0f;
+ float angleThresholdDegrees = 5.0f;
List<Vector2> 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);
}
@@ -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;
@@ -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<HMMRecognizer>();
+ 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);
+ }
}
}
}
Binary file not shown.
@@ -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<HMMRecognizer>();
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);

0 comments on commit f8199a2

Please sign in to comment.