Вы используете старый пакет с именем cognitive_face , который, к сожалению, ожидает, что входным аргументом будет либо имя файла, либо URL.
К счастью, новое имя пакета azure-cognitiveservices-vision-face поддерживает потоки, поэтому, если вы переключитесь, вы можете сделать что-то вроде следующего:
from azure.cognitiveservices.vision.face import FaceClient
from msrest.authentication import CognitiveServicesCredentials
import cv2
import os
face_key = '...' # your API key
face_endpoint = '...' # your endpoint, e.g. 'https://westus.api.cognitive.microsoft.com'
credentials = CognitiveServicesCredentials(face_key)
client = FaceClient(face_endpoint, credentials)
# img is your unencoded (raw) image, from the camera
img = ...
# buf will be the encoded image
ret,buf = cv2.imencode('.jpg', img)
# stream-ify the buffer
stream = io.BytesIO(buf)
# call the Face API
detected_faces = client.face.detect_with_stream(
stream,
return_face_id=True,
return_face_attributes=['age','gender','emotion'])
# access the response, example:
for detected_face in detected_faces:
print('{} happiness probability={}'.format(
detected_face.face_id,
detected_face.face_attributes.emotion.happiness))