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}")