Back to Parent

response = requests.post(face_api_url, params=params, headers=headers, data=image_data)
response.raise_for_status()
faces = response.json()

# Display the original image and overlay it with the face information
image_read = open(image_path, "rb"),read()
image = Image.open(BytesIO(image_read))

plt.figure(figsize=(8,8))
ax = plt.imshow(image, alpha=1)
for face in faces:
    fr = face["faceRectangle"]
    fa = face["faceAttributes"]
    origin = (fr["left"], fr["top"])
    p = patches.Rectangle(
         origin, fr["width"], fr["height"], fill=False, linewidth=2, color='b')
    ax.axes.add_patch(p)
    plt.text(origin[0], origin[1], "%s, %d"%(fa["gender"].capitalize(), fa["age"]), fontsize=20, weight="bold", va="bottom")
_ = plt.axis("off")
plt.show()

print(faces)
print(fa["emotion"])
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0