Forum Discussion

RoboAds's avatar
RoboAds
Copper Contributor
Nov 14, 2019

Azure Face API using python

Hi Team,

Wish to know how to send local image URL to Azure face API. Please find my code below . I am receiving invalid URL error.

please do let me know at your earliest convenience.  Thanks in Advance.

 

Code

 

cam1 = cv2.VideoCapture(1)
while(True):
# Capture frame-by-frame
#ret0, frame0 = cam0.read()
ret1, frame1 = cam1.read()
cv2.imwrite("images/face1.png",frame1)
url = "https://rafaces.cognitiveservices.azure.com/face/v1.0/detect"

querystring = {"q": "requests+language:python","returnFaceAttributes":"age,gender,smile,emotion,glasses,noise","maxNumOfCandidatesReturned ":"Tru","maxNumOfCandidatesReturned%20":"Tru"}

payload = "{\r\n \"url\":\"images/face1.png\"\r\n}"
headers = {
'Content-Type': "application/json",
'Ocp-Apim-Subscription-Key': "7af27b63c4a94e80b8d5d045a6927cd6",
'User-Agent': "PostmanRuntime/7.19.0",
'Accept': "/",
'Cache-Control': "no-cache",
'Postman-Token': "44fbc05f-41ba-40dc-9c8a-72708fc93a3c,af17bcb2-4835-412e-b968-5437592c9fb1",
'Host': "rafaces.cognitiveservices.azure.com",
'Accept-Encoding': "gzip, deflate",
'Content-Length': "84",
'Connection': "keep-alive",
'cache-control': "no-cache"
}

response1 = requests.request("POST", url, data=payload, headers=headers, params=querystring)
json_response = response1.json()
print(json_response)
x = len(json_response)
print(x)
cv2.imshow('image0', frame1)
sleep(10)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

 

 

Response

{'error': {'code': 'InvalidURL', 'message': 'Invalid image URL.'}}

No RepliesBe the first to reply

Resources