Exemple #1
0
def main():
    capture_images()
    aligned = facenet.align_face(images)
    comparisons = facenet.compare(aligned)

    print("Is image 1 and 2 similar? ", bool(comparisons[0][1]))
    print("Is image 1 and 3 similar? ", bool(comparisons[0][2]))
Exemple #2
0
def new_image():
    '''
        Register a new recognition with the currently logged in user
    '''
    recognition_id = request.json.get('recognition_id')
    location = request.json.get('location')
    image_file = request.files['image']
    if recognition_id is None or image_file is None:
        abort(400)  # missing arguments
    aligned = facenet.align_face(image_file)
    encoding = facenet.embedding(aligned)[0]

    image = Image(recognition_id=recognition_id,
                  encoding=encoding,
                  location=location)
    DB.session.add(image)
    DB.session.commit()
    return (jsonify({'encoding': image.encoding}), 201, {
        'Location': url_for('get_image', image_id=image.id, _external=True)
    })
Exemple #3
0
def recognize():
    '''
        See if this user recognizes the given image
    '''
    threshold = 0.7
    images = request.files['image']
    aligned = facenet.align_face(images)

    if aligned == images:
        return jsonify({'is_person': False})

    encoding = facenet.embedding(aligned)[0]
    recognitions = Recognition.query.filter_by(user_id=g.user.id).all()

    closest_diff = 1
    closest_match = None
    for recognition in recognitions:
        diff = 1 - spatial.distance.cosine(encoding, recognition.encoding)
        if diff < threshold and diff < closest_diff:
            closest_match = recognition
    if closest_match is not None:
        return jsonify({'is_person': True, 'recogntion_id': closest_match.id})
    else:
        return jsonify({'is_person': True, 'recogntion_id': -1})
Exemple #4
0
from easyfacenet.simple import facenet
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
images = [
    'images/adi.jpeg', 'images/state.jpeg', 'images/state2.jpeg',
    'images/erik.jpeg', 'images/state3.jpeg'
]
aligned = facenet.align_face(images)
comparisons = facenet.compare(aligned)

print("Is image ADI and ERIK similar? ", bool(comparisons[0][3]))
print("Is image STATE and ERIK similar? ", bool(comparisons[1][3]))
print("Is image STATE and STATE2 similar? ", bool(comparisons[1][2]))
print("Is image STATE and STATE3 similar? ", bool(comparisons[1][4]))
#%%
training_path = "dataset/training"
testing_path = "dataset/testing"

training_pickle_filename = 'training_grey.p'
testing_pickle_filename = 'testing_grey.p'

#%%

print("Procesando testing...")
testing_paths = [
    testing_path + "/" + path for path in os.listdir(testing_path)
    if path.split(".")[1] == "jpg"
]
removed_testing = []
aligned_testing = facenet.align_face(testing_paths, removed_testing)
embs_testing = facenet.embedding(aligned_testing)

print("Testing:")
if len(removed_testing) == 0:
    print(
        f"Todas las caras fueron procesadas! ({len(embs_testing)}/{len(testing_paths)})"
    )
else:
    print(
        f"Ciertas caras ({len(removed_testing)}) no pudieron ser definidas y fueron pobladas con un None.\nEl resto ({len(embs_testing)}/{len(testing_paths)}) fue procesado correctamente"
    )

print("Procesando training...")
training_paths = [
    training_path + "/" + path for path in os.listdir(training_path)