Permalink
Browse files

Plug hand data into the UI

  • Loading branch information...
ssaamm committed Oct 10, 2015
1 parent d83f402 commit 35aac3168fd37a984087dc269607aa815e382fc8
Showing with 39 additions and 19 deletions.
  1. +35 −0 app.py
  2. +2 −2 hand_data.py
  3. 0 {ui → }/static/style.css
  4. +2 −1 {ui → }/templates/ui.html
  5. +0 −16 ui/app.py
35 app.py
@@ -0,0 +1,35 @@
from classifier import clf
from flask import Flask, render_template, jsonify
from hand_data import get_hand_position
from lib import Leap
import random
app = Flask(__name__)
controller = Leap.Controller()
controller.set_policy(Leap.Controller.POLICY_BACKGROUND_FRAMES)
past_symbol = None
@app.route('/')
def hello():
return render_template('ui.html')
@app.route('/current')
def current_symbol():
global past_symbol
hand_pos = get_hand_position(controller)
if not hand_pos:
new = past_symbol != ' '
past_symbol = ' '
return jsonify(symbol=' ', new=new)
features = [v for k, v in hand_pos.iteritems()]
symbol = ''.join(clf.predict(features))
new = past_symbol != symbol
past_symbol = symbol
return jsonify(symbol=symbol, new=new)
if __name__ == '__main__':
app.run(debug=True)
@@ -12,8 +12,8 @@
'''
def get_hand_position(controller):
frame = controller.frame()
while len(frame.fingers) == 0:
frame = controller.frame()
if len(frame.fingers) == 0:
return None
fingers = controller.frame().fingers
finger_bones = []
File renamed without changes.
@@ -7,12 +7,13 @@
$(document).ready(function() {
window.setInterval(function() {
$.get('/current', '', function(data, textStatus, jqXHR) {
console.log(data);
if (data.new) {
$('#translation-text').append(data.symbol);
}
});
$('body').scrollLeft($(document).outerWidth());
}, 400);
}, 1000);
});
</script>
</head>

This file was deleted.

Oops, something went wrong.

0 comments on commit 35aac31

Please sign in to comment.