Python 3.x 如何调用Microsoft cognitive face并将图像作为带有cognitive_face的python字节传递
嗨,在这个问题上我也在尝试同样的事情 将字节图像传递到人脸检测库 但是有了认知面库Python 3.x 如何调用Microsoft cognitive face并将图像作为带有cognitive_face的python字节传递,python-3.x,opencv,microsoft-cognitive,face-api,Python 3.x,Opencv,Microsoft Cognitive,Face Api,嗨,在这个问题上我也在尝试同样的事情 将字节图像传递到人脸检测库 但是有了认知面库 faces =CF.face.detect(buf.tobytes(),True,False,attributes='age,gender,emotion') 但是我犯了一个错误 回溯(最后一次调用):文件“\cam.py”,第80行,在faces=CF.face.detect(buf.tobytes(),True,False,attributes='age,gender,headPose,smile>,fac
faces =CF.face.detect(buf.tobytes(),True,False,attributes='age,gender,emotion')
但是我犯了一个错误
回溯(最后一次调用):文件“\cam.py”,第80行,在faces=CF.face.detect(buf.tobytes(),True,False,attributes='age,gender,headPose,smile>,facialHair,眼镜,情感,头发,化妆,遮挡,附件,模糊,曝光,n>oise')文件“Python37\lib\site packages\conceptive\u face\face.py”,第33行,在detection headers,data,json=util.parse_image(image)文件“Python37\lib\site packages\cognitive_face\util.py”,第133行,位于parse_image elif os.path.isfile(image):#当image是文件路径时。文件“Python37\lib\genericpath.py”,第30行,在isfile st=os.stat(path)ValueError:stat:path中嵌入空字符
您正在使用名为的旧包,不幸的是,该包希望输入参数为文件名或URL 幸运的是,新的包名支持streams,因此如果切换,可以执行以下操作:
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))