Skip to content

Commit

Permalink
hmm implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown authored and unknown committed May 15, 2012
1 parent bb50912 commit f8199a2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
8 changes: 4 additions & 4 deletions unity_project/Assets/Gesture Recognition/GestureRecognizer.cs
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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);
}
Expand Down
6 changes: 2 additions & 4 deletions unity_project/Assets/Gesture Recognition/HMMRecognizer.cs
Expand Up @@ -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){
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 13 additions & 10 deletions unity_project/Assets/Other/Scripts/WiiReader.cs
Expand Up @@ -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);
}
}
}
}
Expand Down
Binary file modified unity_project/Assets/player/prefabs/player.prefab
Binary file not shown.
16 changes: 8 additions & 8 deletions unity_project/Assets/player/scripts/playerAttack.cs
Expand Up @@ -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);
Expand Down

0 comments on commit f8199a2

Please sign in to comment.