gestures

[unmaintained] PoC for motion gesture detection from webcam input
Log | Files | Refs | README | LICENSE

commit 734697eff1806a97cc2ac4d5a3112d3056cdd438
parent fc9c6b2e96877c47883d8cdd1037d6e1df8743ec
Author: Stefan Koch <taikano@lavabit.com>
Date:   Sat, 22 Jun 2013 15:30:30 +0200

normalize values for transition matrix

Diffstat:
Mmodels.py | 19+++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/models.py b/models.py @@ -27,10 +27,25 @@ def uniq_list(seq): seen = set() return [x for x in seq if x not in seen and not seen.add(x)] +def normalize_rows(matrix): + new_matrix = [] + + for row in matrix: + div = sum(row) + new_matrix.append([]) + + for elem in row: + if div != 0: + new_matrix[-1].append(float(elem)/div) + else: + new_matrix[-1].append(elem) + + return new_matrix + # TODO: Zuordnung von Indizes stimmt noch nicht def transition_matrix(gesture): gestes = uniq_list(gesture) - A = [[0.1 for i in range(GESTES_COUNT)] for j in range(GESTES_COUNT)] + A = [[0 for i in range(GESTES_COUNT)] for j in range(GESTES_COUNT)] # self transitions are high for geste in gestes: A[geste][geste] = 0.7 @@ -45,7 +60,7 @@ def transition_matrix(gesture): # ending element has no transitions anymore, so give it one A[gestes[-1]][gestes[-1]] = 1 - return A + return normalize_rows(A) def emission_matrix(): B = [[float(1)/OBSERVATIONS_COUNT for i in range(OBSERVATIONS_COUNT)] for j in range(GESTES_COUNT)]