Face Detection API Error

Elif Kalkan 5 Reputation points
2023-05-10T22:12:43.29+00:00

I am trying to use the Azure face detection API only to detect faces in an image but I am getting the following API error:

Traceback (most recent call last):  File "main.py", line 14, in <module>    detected_faces = face_client.face.detect_with_url(image_path)  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/azure/cognitiveservices/vision/face/operations/_face_operations.py", line 547, in detect_with_url    raise models.APIErrorException(self._deserialize, response)azure.cognitiveservices.vision.face.models._models_py3.APIErrorException: (InvalidRequest) Invalid request has been sent.

Below is my code:

from azure.cognitiveservices.vision.face import FaceClientfrom msrest.authentication import CognitiveServicesCredentials

SUBSCRIPTION_KEY = 'X'
ENDPOINT = 'Y'

# Create an authenticated FaceClient.
face_client = FaceClient(ENDPOINT, CognitiveServicesCredentials(SUBSCRIPTION_KEY))


# Detect faces in an image 
fileimage_path = 'test.jpg'
with open(image_path, 'rb') as image_file:    
	detected_faces = face_client.face.detect_with_url(image_path)


# Print the face IDs and locations
for face in detected_faces:    
	print(f"Face ID: {face.face_id}")    
  	print(f"Face location: x={face.face_rectangle.left}, y={face.face_rectangle.top}, w=		  {face.face_rectangle.width}, h={face.face_rectangle.height}")
Azure Face
Azure Face
An Azure service that provides artificial intelligence algorithms that detect, recognize, and analyze human faces in images.
165 questions
{count} vote

1 answer

Sort by: Most helpful
  1. William Krinsman 105 Reputation points
    2024-03-15T16:12:07.43+00:00

    The answers given above are wrong, the problem is that the default value of

    return_face_id

    in both detect_with_url and detect_with_stream is True, but returning face ID's is now a restricted feature.

    So for all calls of detect_with_url and detect_with_stream , you have to manually / explicitly set return_face_id to False , e.g.

    detect_with_stream(..., return_face_id=False)

    Compare:

    https://learn.microsoft.com/en-us/answers/questions/1179278/azure-face-api-invalid-request-json-parsing-error?page=1&orderby=Helpful&comment=answer-1175171#newest-answer-comment

    https://learn.microsoft.com/en-us/python/api/azure-cognitiveservices-vision-face/azure.cognitiveservices.vision.face.operations.faceoperations?view=azure-python-preview

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.