Esempio n. 1
0
def crop_head(message):
    last_image = message['hack']['last_image']
    last_image_at = message['hack']['last_image_at']
    last_skeleton = message['hack']['last_skeleton']
    last_skeleton_at = message['hack']['last_skeleton_at']

    # No image means nothing to crop, se we're done.
    if last_image is None:
        return None

    cropped_head = None

    # If this is an image, and we have a "recent" skeleton, or vice-versa
    # try to crop the face. For this, we need to have
    # at least one skeleton and one image.
    if last_skeleton is not None:
        if abs(last_image_at - last_skeleton_at) < MAX_TIME:
            logger.info("Trying to crop head using correlation between "
                        "skeleton and RGB image (skeleton_ts = %d, "
                        "image_ts = %d)" % (last_skeleton_at, last_image_at))
            cropped_head = _crop_head_using_skeleton(last_image, last_skeleton)
        else:
            logger.info("Cannot crop head using correlation between skeleton "
                        "and image because they are too far apart. "
                        "(skeleton_ts = %d, image_ts = %d)" %
                        (last_skeleton_at, last_image_at))
            cropped_head = _crop_head_using_face_detection(last_image)

    # If we have no "recent" skeleton or no skeleton at all,
    # we'll detect the face from image
    else:
        logger.info("We have no skeleton so far, so we're using face "
                    "detection in order to crop the head")
        cropped_head = _crop_head_using_face_detection(last_image)

    if cropped_head is not None:
        logger.info("%s gave us a face to recognize!" % message['sensor_id'])
        return image_to_base64(cropped_head)
    else:
        return None
Esempio n. 2
0
def one_by_one_image(_):
    return image_to_base64(Image.frombuffer(
        'RGB', (1, 1), base64.b64decode('AAAA'), 'raw', 'RGB', 0, 1))