Search code examples
pythonazureazure-cognitive-servicesface-api

Azure Face API, python SDK attribute url


I'm using the Python SDK snippet provided by Azure docs.

BASE_URL ="https://eastus.api.cognitive.microsoft.com/face/v1.0/
CF.BaseUrl.set(BASE_URL)

I want to return face attributes, The docs referenced here suggest that adding

/detect[&returnFaceAttributes=age,gender]

To the Base URl will return age and gender attributes. It's throwing me an error, am I missing something?

This is my first time using Azure Face API.


Solution

  • We could use the follow code to get the returnFaceAttributes

    faces = CF.face.detect(img_url,attributes='age,gender')
    

    Whole demo code

    import cognitive_face as CF
    KEY = 'xxxxx'  # Replace with a valid subscription key (keeping the quotes in place).
    CF.Key.set(KEY)
    BASE_URL = 'https://{location}.api.cognitive.microsoft.com/face/v1.0'  # Replace with your regional Base URL
    CF.BaseUrl.set(BASE_URL)
    #You can use this example JPG or replace the URL below with your own URL to a JPEG image.
    img_url = 'https://raw.githubusercontent.com/Microsoft/Cognitive-Face-Windows/master/Data/detection1.jpg'
    faces = CF.face.detect(img_url,attributes='age,gender')
    

    Test Result:

    enter image description here