Python error TypeError: string indications must be integrers

Asked 2 years ago, Updated 2 years ago, 88 views

I'm using Azure's FaceAPI, but I'm a beginner, so I don't understand the details of the script or the meaning of the error.I searched, but it was difficult to understand.
Can someone tell me how to solve it?

Error Contents

Traceback (most recent call last):
  File "face.py", line 29, in <module>
    fr = face ["faceRectangle" ]
TypeError: string indications must be integrers

Code

import requests
import matplotlib.pyplot asplt
from PIL import Image
from matplotlib import patches
from io import BytesIO

subscription_key="****************"
assert subscription_key

face_api_url='https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect'

image_url='https://how-old.net/Images/faces2/main007.jpg'

headers = {'Ocp-Apim-Subscription-Key': '********'}
param={
    'returnFaceId': 'true',
    'returnFaceLandmarks': 'false',
    'returnFaceAttributes': 'age, gender, headPose, smile, facialHair, classes, '+
    'emotion, hair, makeup, occlusions, accessories, blur, exposure, noise'
}
data={'url':image_url}
response=requests.post(face_api_url, params=params, heads=headers, json=data)
faces=response.json()

image=Image.open(BytesIO(requests.get(image_url).content))
plt.figure(figsize=(8,8))
ax=plt.imshow (image, alpha=0.6)
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")

python azure

2022-09-30 18:07

1 Answers

I think the questioner expects faces to be listed in the dictionary, but it seems to be a dictionary.

This post was edited based on @mjy's Comment and posted as Community Wiki.This post was edited based on @mjy's Comment and posted as Community Wiki.


2022-09-30 18:07

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.