Ejemplo n.º 1
0
def betaface_recognition(image_dict):
    """ Given a message contained a cropped head, send it to BetaFace
        API for face recognition. This can take anywhere from 1 to 10 seconds.
    """
    try:
        api = BetaFaceAPI()

        # Get image from message, save it to disk and
        # pass it on to BetaFace API
        image = base64_to_image(image_dict['head_image']['image'],
                                int(image_dict['head_image']['width']),
                                int(image_dict['head_image']['height']))
        temp_path = random_file_name('jpg', "FR_")
        logger.info("Generated random path to save image: %s" % temp_path)
        image = image.rotate(180)
        image.save(temp_path)

        logger.info("Saved image to disk at path %s" % temp_path)

        matches = api.recognize_faces(temp_path, 'amilab.ro')
        logger.info("Received recognized faces from BetaFace API %r" % matches)

        #os.remove(str(temp_path))
        #logger.info("Removed image from disk (%s)" % str(temp_path))

        return matches
    except:
        logger.exception("Failed to recognize faces via BetaFace API")
        return {}
Ejemplo n.º 2
0
def _crop_head_using_face_detection(last_image):
    """ Given the last image, try to detect any faces in it
        and crop the first one of them, if any. """
    image = base64_to_image(last_image['image'],
                            int(last_image['width']),
                            int(last_image['height']),
                            last_image['encoder_name'])
    return crop_face_from_image(image)
Ejemplo n.º 3
0
def _crop_head_using_skeleton(last_image, last_skeleton):
    """ Given the last image and last skeleton which are
        'close enough' apart, crop off an image of the head. """
    image = base64_to_image(last_image['image'],
                            int(last_image['width']),
                            int(last_image['height']),
                            last_image['encoder_name'])
    skeleton = last_skeleton

    return crop_head_using_skeleton(image, skeleton)