Exemple #1
0
def get_faces(path):
    print "getting faces"
    path = MEDIA_ROOT + "/" + path
    with open(path, 'rb') as img:
        bimage = base64.b64encode(img.read())

    Algorithmia.apiKey = 'Simple totally_real_api_key'
    result = Algorithmia.algo('/ANaimi/FaceDetection').pipe(bimage)

    faces = []
    for rect in result:
        print "found face"
        face = Face()
        face.name = "Anon"
        face.x = rect['x']
        face.y = rect['y']
        face.width = rect['width']
        face.height = rect['height']
        faces.append(face)
        Face.save(face)
    return faces
Exemple #2
0
def get_faces(photo):
    import Algorithmia
    import base64
    Algorithmia.apiKey = os.environ.get('ALGORITHMIA_KEY')

    with default_storage.open(photo.img.name, 'rb') as img:
        b64 = base64.b64encode(img.read())

    rectangles = Algorithmia.algo("/ANaimi/FaceDetection/0.1.2").pipe(b64)

    faces = []
    for rect in rectangles:
        face = Face()
        face.photo = photo
        face.name = '?'
        face.x = rect['x']
        face.y = rect['y']
        face.width = rect['width']
        face.height = rect['height']
        face.save()
        faces.append(face)
    return faces