Привет, я пытаюсь сделать то же самое в этом вопросе Как я могу передать изображение захвата непосредственно как двоичные данные для обработки в вызове API (Microsoft Cognitive Services) с использованием Python передача байтового изображения в библиотеку обнаружения лиц но с библиотекойcognitive_face
faces =CF.face.detect(buf.tobytes(),True,False,attributes='age,gender,emotion')
но получаю ошибку
Traceback (most recent call last): File ".\cam.py", line 80, in faces = CF.face.detect(buf.tobytes(),True,False,attributes='age,gender,headPose,smile>,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,n>oise') File "Python37\lib\site-packages\cognitive_face\face.py", line 33, in detect headers, data, json = util.parse_image(image) File "Python37\lib\site-packages\cognitive_face\util.py", line 133, in parse_image elif os.path.isfile(image): # When image is a file path. File "Python37\lib\genericpath.py", line 30, in isfile st = os.stat(path) ValueError: stat: embedded null character in path
Вы используете старый пакет с именем когнитивное_лицо, который, к сожалению, ожидает, что входной аргумент будет либо именем файла, либо 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))