gpt4 book ai didi

python - 如何使用 Azure API 检测情绪?

转载 作者:行者123 更新时间:2023-12-03 05:38:55 28 4
gpt4 key购买 nike

我想创建一个简单的 Python 应用程序,通过 Azure Face/Emotions API 识别给定 URL 中的面部表情。我正在关注此文档:

到目前为止,我完成了人脸识别部分,但我有点困惑如何调用情感模型并显示结果。

import urllib.request  
from azure.cognitiveservices.vision.face import FaceClient
from azure.cognitiveservices.vision.face.models import Emotion
from msrest.authentication import CognitiveServicesCredentials

# Image
URL = "https://upload.wikimedia.org/wikipedia/commons/5/55/Dalailama1_20121014_4639.jpg"

# API
KEY = "xxx"
ENDPOINT = "https://happyai.cognitiveservices.azure.com/"

# Now there is a trained endpoint that can be used to make a prediction
predictor = FaceClient(ENDPOINT, CognitiveServicesCredentials(KEY))

detected_faces = predictor.face.detect_with_url(url=URL)
if not detected_faces:
raise Exception('No face detected from image {}'.format(URL))

# Display the detected face ID in the first single-face image.
# Face IDs are used for comparison to faces (their IDs) detected in other images.
print('Detected face ID from', URL, ':')
for face in detected_faces: print (face.face_id)
print()

# Save this ID for use in Find Similar
first_image_face_ID = detected_faces[0].face_id

# Call Emotion model

# Display the results.

任何帮助将不胜感激。谢谢!

最佳答案

您可以使用以下代码进行情绪检测,

def det_emotion(self, frame, count):

image_path = self.path_folder + "/img/frame%d.jpg" % count
image_data = open(image_path, "rb")

params = {
'returnFaceId': 'true',
'returnFaceLandmarks': 'false',
'returnRecognitionModel':'false',
}

response = requests.post(self.face_api_url, params=params,data=image_data)
response.raise_for_status()
faces = response.json()
frame = self.add_square(frame, faces)

return frame

关于python - 如何使用 Azure API 检测情绪?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60297693/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com