Skip to content

Instantly share code, notes, and snippets.

@easonlai
Last active February 13, 2021 09:45
Show Gist options
  • Save easonlai/136b41f425aa4445e5bab9d5df223965 to your computer and use it in GitHub Desktop.
Save easonlai/136b41f425aa4445e5bab9d5df223965 to your computer and use it in GitHub Desktop.
# While loop to continuously process the video frames
while True:
ret, frame = cam.read()
if not ret:
print("failed to grab frame")
break
cv2.imshow("face", frame)
# Post video frames to Azure Face Service to obtain face landmarks
image = cv2.imencode('.jpg', frame)[1].tostring()
subscription_key = KEY
face_api_url = "https://southeastasia.api.cognitive.microsoft.com/face/v1.0/detect"
headers = {'Content-Type': 'application/octet-stream', 'Ocp-Apim-Subscription-Key': subscription_key}
params = {'returnFaceId': 'true', 'returnFaceLandmarks': 'true'}
response = requests.post(face_api_url, params=params, headers=headers, data=image)
response.raise_for_status()
faces = response.json()
print(faces)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment