commit 3e28b12f104248f5a8b6e83cb0aa3ea6a84b04b5
parent 635f4c85893f175235ca72b01f9716c1eb96e347
Author: Stefan Koch <taikano@lavabit.com>
Date: Wed, 12 Jun 2013 20:00:25 +0200
add 8 instead of 4 directions
Diffstat:
2 files changed, 28 insertions(+), 21 deletions(-)
diff --git a/models.py b/models.py
@@ -4,8 +4,12 @@ UP = 0
DOWN = 1
LEFT = 2
RIGHT = 3
-GESTES_COUNT = 4
-OBSERVATIONS_COUNT = 4
+UP_RIGHT = 4
+UP_LEFT = 5
+DOWN_RIGHT = 6
+DOWN_LEFT = 7
+GESTES_COUNT = 8
+OBSERVATIONS_COUNT = 8
gestures = [
([UP, RIGHT], ['/usr/bin/xdotool', 'getactivewindow', 'windowkill']),
@@ -39,25 +43,25 @@ def emission_matrix(gesture):
for geste in gestes:
if geste == UP:
- B[geste] = [0.5, 0.1, 0.2, 0.2]
+ B[geste] = [0.5, 0.05, 0.1, 0.1, 0.2, 0.2, 0.1, 0.1]
elif geste == DOWN:
- B[geste] = [0.1, 0.5, 0.2, 0.2]
+ B[geste] = [0.05, 0.5, 0.1, 0.1, 0.1, 0.1, 0.2, 0.2]
elif geste == LEFT:
- B[geste] = [0.2, 0.2, 0.5, 0.1]
+ B[geste] = [0.1, 0.1, 0.5, 0.05, 0.1, 0.2, 0.1, 0.2]
else:
- B[geste] = [0.2, 0.2, 0.1, 0.5]
-
+ B[geste] = [0.1, 0.1, 0.05, 0.5, 0.2, 0.1, 0.2, 0.1]
+ print(B)
return B
def initial_vector(gesture):
- vec = [0 for i in range(4)]
+ vec = [0 for i in range(GESTES_COUNT)]
vec[gesture[0]] = 1
return vec
# Construct parameters
models = []
-sigma = ghmm.IntegerRange(0, 4)
+sigma = ghmm.IntegerRange(0, 8)
for gesture in gestures:
# transition matrix
A = transition_matrix(gesture[0])
diff --git a/track.py b/track.py
@@ -7,11 +7,6 @@ import numpy
import ghmm
import models
-UP = 0
-DOWN = 1
-LEFT = 2
-RIGHT = 3
-
path = []
def diffImg(t0, t1, t2):
@@ -34,14 +29,22 @@ def pointer_pos(img):
def movement_direction(x_delta, y_delta):
if abs(x_delta) > 10 or abs(y_delta) > 10:
degree = math.atan2(y_delta, x_delta)
- if -0.75 * math.pi <= degree < -0.25 * math.pi:
- direction = UP
- elif -0.25 * math.pi <= degree < 0.25 * math.pi:
- direction = LEFT
- elif 0.25 * math.pi <= degree < 0.75 * math.pi:
- direction = DOWN
+ if -0.875 * math.pi <= degree < -0.625 * math.pi:
+ direction = models.UP_RIGHT
+ elif -0.625 * math.pi <= degree < -0.375 * math.pi:
+ direction = models.UP
+ elif -0.375 * math.pi <= degree < -0.125 * math.pi:
+ direction = models.UP_LEFT
+ elif -0.125 * math.pi <= degree < 0.125 * math.pi:
+ direction = models.LEFT
+ elif 0.125 * math.pi <= degree < 0.375 * math.pi:
+ direction = models.DOWN_LEFT
+ elif 0.375 * math.pi <= degree < 0.625 * math.pi:
+ direction = models.DOWN
+ elif 0.625 * math.pi <= degree < 0.875 * math.pi:
+ direction = models.DOWN_RIGHT
else:
- direction = RIGHT
+ direction = models.RIGHT
return direction
else: