예제 #1
0
파일: app.py 프로젝트: skyli42/RiceKrispies
def store_password():
    """
    Gets an image and then detects the face.  If the database is empty, then it immediately prompts for your name to create a new
    profile.  If the database is not empty but the computer can not recognize you, it prompts for your name to create a new profile. 
    Otherwise, it asks you which website do you want to save the password to.   
    """
    global descript
    global Boolean 
    global FaceGot
    img_array = get_image()
    FaceGot = detect(img_array, False)
    if (len(FaceGot) > 1):
        return statement("Sorry there are multiple people behind you")
    global BestMatch
    #print(len(db.profiles), flush = True)
    if (not(len(db.profiles)) == 0):
        #print((FaceGot[0])[0],flush = True)
        BestMatch = db.computeMatches((FaceGot[0])[0], db.profiles)
        #print(BestMatch, flush = True)
        if (BestMatch in db.profiles):
            msg = "What website do you want to save a password to. After you enter a website, follow the instructions in the computer console"
            return question(msg)
        else:
            Boolean = True
            msg = "Tell me your name"
            return question(msg)
    else: 
        Boolean = True
        msg = "Tell me your name"
        return question(msg)
예제 #2
0
파일: app.py 프로젝트: vltanh/narupedia
def process_query(bot_id, file, name):
    try:
        bot = User.query.filter(User.id == bot_id).one()
    except NoResultFound:
        print('Error! No bot (yet).')
    except MultipleResultsFound:
        print('Error! Wait what?')

    try:
        model = yolo.get_model(bot.username)
    except:
        print('Error! Cannot get model!')

    inp_dir = './data/input/{}.jpg'.format(name)
    out_dir = './data/output/{}'.format(name)
    file.save(inp_dir)
    r = yolo.detect(model, inp_dir, out_dir=out_dir)

    r = [x for x in r if x['prob'] > 0.3]
    messages = []
    messages.append('I have detected %d object(s) in the images.' % len(r))
    for idx, det in enumerate(r):
        prob = det['prob']
        if prob > 0.8:
            messages.append('[%d] I detected a [%s].' % (idx, det['class']))
        elif prob > 0.5:
            messages.append('[%d] I am not so sure but it may be a [%s]' %
                            (idx, det['class']))
        elif prob > 0.3:
            messages.append(
                '[%d] I really do not know what this is. My best guess is that it is a [%s].'
                % (idx, det['class']))

    inp_token = upload_file('input', inp_dir)
    out_token = upload_file('output', out_dir + '.jpg')

    inp_url = 'https://firebasestorage.googleapis.com/v0/b/narupedia-d9cf9.appspot.com/o/input%2F' + name + '.jpg?alt=media&token=' + inp_token
    out_url = 'https://firebasestorage.googleapis.com/v0/b/narupedia-d9cf9.appspot.com/o/output%2F' + name + '.jpg?alt=media&token=' + out_token

    return inp_url, out_url, messages
예제 #3
0
파일: app.py 프로젝트: skyli42/RiceKrispies
def retrieve_passwords():
    """
    Takes an image and then detects the face in the image.  After, find the best match for the person in the image. Then, retrieves
    the person corresponding to the password. Goes through the password and determines if the password is weak or strong.  If the 
    password is weak, Alexa says the password outloud forcing you to change the password.  It then prints out all the passwords 
    corresponding to your name. If the person is not recognized, Alexa will not allow you to see the passwords.   

    Returns: All weak passwords OR an error message
    """
    img_array = get_image()
    global BestMatch
    faceGot = detect(img_array, False)
    if (len(FaceGot) > 1):
        return statement("Sorry there are multiple people behind you")
    descript = faceGot[0]
    BestMatch = db.computeMatches(descript[0], db.profiles)
    global Passwords 
    if (BestMatch.passwords is not None):
        #print(BestMatch, flush = True)
        Passwords = list(BestMatch.passwords) 
        passwords = BestMatch.passwords
        #print(passwords, flush = True)
        scores = password_strengths()
        #print(scores, flush = True)
        msg = ""
        if (not(len(scores) == 0)):
            msg += "You have a weak password, it is"
        for i, score in enumerate(scores):
            if score < 40:
                indexer = Passwords[i].index(":")
                msg += " {} and".format((Passwords[i])[indexer+1 : ])
        msg += " I printed out all the passwords for you"
        return statement(msg)
    else:
        msg = "I don't recognize you, stop trying to hack into passwords"
        return statement(msg)   
예제 #4
0
# -*- coding: utf-8 -*-
import numpy as np
import module
import tovrml
import cv2

raw_data = module.get_data('map40.dat')
shape = (924, 1130)

data = module.error_erase(raw_data, shape)

predict1 = module.detect(data, shape, 0.8, 5, (20, 20), 9)
predict2 = cv2.imread('nnpredict.png', 0)
score1 = module.score(predict1)
score2 = module.score(predict2)
if score1[0] > score2[0]: 
    predict = predict1
else: 
    predict = predict2

com_data, com_shape = module.compress(data, shape, (2, 2), (2, 2), 'median')
com_predict = module.array_compress(predict, shape, (2, 2), (2, 2))

mask = com_predict.astype(bool).reshape(-1)
struct, land = com_data[mask], com_data[~mask]

struct = module.smooth(struct, com_shape, 3, 'max')
land = module.smooth(land, com_shape, 3, 'min')
smooth_data = module.concat(struct, land)

generate = module.generate(smooth_data, com_predict)
예제 #5
0
파일: app.py 프로젝트: vltanh/narupedia
def send_file():
    request_data = request.form
    from_user = request_data.get('from_user', '')
    to_user = request_data.get('to_user', '')
    channel = request_data.get('channel')

    file = request.files['file']

    bot_id = to_user
    name = channel + datetime.datetime.now().strftime("%Y%m%d%H%M%S")

    inp_dir = './data/input/{}.jpg'.format(name)
    file.save(inp_dir)
    inp_token = upload_file('input', inp_dir)
    inp_url = 'https://firebasestorage.googleapis.com/v0/b/narupedia-d9cf9.appspot.com/o/input%2F' + name + '.jpg?alt=media&token=' + inp_token
    inp_img = create_message(message=inp_url,
                             type='Image',
                             to_user=to_user,
                             from_user=from_user,
                             channel=channel)
    pusher.trigger(channel, 'new_message', inp_img)

    message = create_message(message="I'm onto it, please wait for a bit.",
                             type='Text',
                             to_user=from_user,
                             from_user=to_user,
                             channel=channel)
    pusher.trigger(channel, 'new_message', message)

    try:
        bot = User.query.filter(User.id == bot_id).one()
    except NoResultFound:
        print('Error! No bot (yet).')
    except MultipleResultsFound:
        print('Error! Wait what?')

    try:
        model = yolo.get_model(bot.username)
    except:
        print('Error! Cannot get model!')

    out_dir = './data/output/{}'.format(name)
    r = yolo.detect(model, inp_dir, out_dir=out_dir)
    r = [x for x in r if x['prob'] > 0.5]
    messages = []
    messages.append('I have detected %d object(s) in the images.' % len(r))
    for idx, det in enumerate(r):
        prob = det['prob']
        if prob > 0.8:
            messages.append('[%d] I detected a [%s].' % (idx, det['class']))
        elif prob > 0.5:
            messages.append('[%d] I am not so sure but it may be a [%s]' %
                            (idx, det['class']))
        # elif prob > 0.3:
        # messages.append('[%d] I really do not know what this is. My best guess is that it is a [%s].' % (idx, det['class']))

    out_token = upload_file('output', out_dir + '.jpg')
    out_url = 'https://firebasestorage.googleapis.com/v0/b/narupedia-d9cf9.appspot.com/o/output%2F' + name + '.jpg?alt=media&token=' + out_token

    # inp_url, out_url, messages = process_query(bot_id, file, name)
    out_img = create_message(message=out_url,
                             type='Image',
                             to_user=from_user,
                             from_user=to_user,
                             channel=channel)
    pusher.trigger(channel, 'new_message', out_img)

    for m in messages:
        message = create_message(message=m,
                                 type='Text',
                                 to_user=from_user,
                                 from_user=to_user,
                                 channel=channel)
        pusher.trigger(channel, 'new_message', message)

    return jsonify(messages)