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"
示例#2
0
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"
示例#3
0
文件: app.py 项目: onddi/Sign-Chat
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")
示例#4
0
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)
示例#5
0
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
示例#7
0
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
示例#8
0
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)
示例#9
0
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)
示例#10
0
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)
示例#11
0

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
示例#12
0
def worker():
    data = get_hand_position(controller, blocking=True)
    return model.predict(data)[0]