Example #1
0
def reKognition(PERSONS_FILE, keyp):
    for (name, fn) in PERSONS_FILE:
        # upload image and get analysis result
        with open(fn, "rb") as image_file:
            encoded_string = base64.b64encode(image_file.read())
        json_resp = requests.post(
            "http://rekognition.com/func/api/",
            data={
                "api_key": ReKognition_API_KEY,
                "api_secret": ReKognition_API_SECRET,
                "jobs": "face_part_detail_gender_age_emotion_race_glass_mouth_open_wide_eye_closed_mustchae_beard_sunglasses_recognize_beauty",
                "base64": encoded_string,
            },
        )
        result = json.loads(json_resp.text)

        print_result("", result)

        # elimit inaccurately detected face
        result = elimit_wrong(name, keyp, result)

        # modify the original image
        img = Image.open(fn)
        img = imgproc.draw_box(img, result["face_detection"])
        return img