gestures

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

commit a0dd6fde57ce762301d09dc43dae8aee5d2efe8b
parent 9b9182d168f954a5c26d64012680b16534e28265
Author: Stefan Koch <taikano@lavabit.com>
Date:   Sat, 15 Jun 2013 17:30:43 +0200

save training data and train model in one step

Diffstat:
Mmodels.py | 17++++++++++-------
Mtrack.py | 6++----
2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/models.py b/models.py @@ -20,6 +20,8 @@ gestures = [ ([UP], ['amixer', 'set', 'Master', '10%+']), ] +training_data = [[] for gesture in gestures] + # TODO: Zuordnung von Indizes stimmt noch nicht def transition_matrix(gesture): gestes = list(set(gesture)) @@ -66,15 +68,16 @@ models = [] sigma = ghmm.IntegerRange(0, 8) i = 0 for gesture in gestures: - if not os.path.isfile('/'.join(('models', str(i)))): - A = transition_matrix(gesture[0]) - B = emission_matrix(gesture[0]) - pi = initial_vector(gesture[0]) - else: - with open('/'.join(('models', str(i)))) as f: - (A, B, pi) = simplejson.load(f) + A = transition_matrix(gesture[0]) + B = emission_matrix(gesture[0]) + pi = initial_vector(gesture[0]) m = ghmm.HMMFromMatrices(sigma, ghmm.DiscreteDistribution(sigma), A, B, pi) + + if os.path.isfile('/'.join(('models', str(i)))): + with open('/'.join(('models', str(i)))) as f: + training_data[i] = simplejson.load(f) + m.baumWelch(ghmm.SequenceSet(sigma, training_data[i])) print(m) models.append((m, gesture[1])) diff --git a/track.py b/track.py @@ -125,15 +125,13 @@ while True: if train_mode == False: execute(ghmm.EmissionSequence(models.sigma, path), models.models) else: + models.training_data[train_target].append(path) print("Training model %d" % (train_target,)) - train(ghmm.EmissionSequence(models.sigma, path), models.models[train_target][0]) train_mode = False print("Leaving training mode") - print(models.models[train_target][0]) with open("/".join(('models', str(train_target))), 'w') as f: - (A, B, pi) = tuple(models.models[train_target][0].asMatrices()) - simplejson.dump((A, B, pi), f) + simplejson.dump(models.training_data[train_target], f) path = [] not_changed = 0