def train_char(training_char): controller = Leap.Controller() for t in range(NUM_SAMPLES): time.sleep(SAMPLE_DELAY) sample = get_hand_position(controller, True) while len(sample) != NUM_FEATURES: print "Please place only right hand in view" sample = get_hand_position(controller, True) print sample add_data(sign=training_char, **sample) print "Done training"
def train_char(model_name, training_word): for t in range(NUM_SAMPLES): time.sleep(SAMPLE_DELAY) sample = get_hand_position(controller, True) while len(sample) != NUM_FEATURES: emit(ACTION_TRAINING_ERROR, "Please place only right hand in view") # print "Please place only right hand in view" sample = get_hand_position(controller, True) print sample if t % 10 == 0: emit(ACTION_TRAINING_INPROGRESS, str(t) + "/" + str(NUM_SAMPLES)) add_data(model_name=model_name, sign=training_word, **sample) emit(ACTION_TRAINING_DONE, "Done training")
def train(): train_gui = TrainGUI() controller = Leap.Controller() print("Please show your hand") for t in range(NUM_SAMPLES): print('Getting hand data..') sample = get_hand_position(controller, True) while len(sample) != NUM_FEATURES: print "Please place only right hand in view" sample = get_hand_position(controller, True) print(sample) print "Please submit and try again.." train_gui.run(sample) time.sleep(SAMPLE_DELAY)
def current_symbol(): global past_symbol global prev_prediction hand_pos = get_hand_position(controller) if not hand_pos: new = past_symbol != ' ' past_symbol = ' ' features = [v for k, v in hand_pos.iteritems()] prediction = ''.join(clf.predict(features)) if prediction != prev_prediction: text.append(prediction) prev_prediction = prediction
def guess_char(): global prev controller = Leap.Controller() controller.set_policy(Leap.Controller.POLICY_BACKGROUND_FRAMES) classes = clf.classes_ probs = zip( classes, clf.predict_proba([ v for k, v in get_hand_position(controller, True).iteritems() ])[0]) alpha = max([score for sym, score in probs]) most_probable = sorted([(sym, alpha * score + (1 - alpha)) for sym, score in probs], key=lambda t: t[1], reverse=True) print most_probable[:3] prev = most_probable[0][0] print prev
def guess_char(): global prev controller = Leap.Controller() controller.set_policy(Leap.Controller.POLICY_BACKGROUND_FRAMES) classes = clf.classes_ probs = zip(classes, clf.predict_proba([v for k, v in get_hand_position(controller, True).iteritems()])[0]) alpha = max([score for sym, score in probs]) most_probable = sorted([(sym, alpha * score + (1 - alpha)) for sym, score in probs], key=lambda t: t[1], reverse=True) print most_probable[:3] prev = most_probable[0][0] print prev
def current_symbol(): global past_symbol global prev_prediction # Is there a hand? 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()] # Do we have a new symbol? prediction = ''.join(clf.predict(features)) if prediction == prev_prediction: # We good fam return jsonify(new=False, symbol=prediction) else: prev_prediction = prediction return jsonify(new=True, symbol=prediction)
def current_symbol(): global past_symbol global prev_prediction #detect if there is a hand hand_pos = get_hand_position(controller) if not hand_pos: new = past_symbol != '%' past_symbol = ' ' return jsonify(symbol='bleh', new=new) features = np.array([v for k, v in hand_pos.iteritems()]).reshape(1, -1) prediction = ''.join(clf.predict(features)) if prediction == prev_prediction: return jsonify(new=False, symbol=prediction) else: prev_prediction = prediction return jsonify(new=True, symbol=prediction)
def send_data(data): print data h = httplib.HTTPConnection(IP_ADDR) headers = {"Content-Type": "application/x-www-form-urlencoded"} h.request('POST', '/', urllib.urlencode({'data': data}), headers) r = h.getresponse() time.sleep(2) p = vlc.MediaPlayer( "file:///home/gautham/temp/sign-language-tutor/alexa_call.m4a") p.play() while True: try: hand_pos = get_hand_position(controller) if hand_pos is None: continue features = [v for k, v in hand_pos.iteritems()] prediction = ''.join(clf.predict(features)) time.sleep(1) if prediction != prev_prediction: prev_prediction = prediction send_data(dictmapping[prediction]) time.sleep(10) # print dictmapping[prediction] except Exception as ex: print(ex.message) continue
def worker(): data = get_hand_position(controller, blocking=True) return model.predict(data)[0]