在python中使用微软的FaceApi比较人脸

2024-04-20 15:29:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python编程新手,只是想知道是否可以使用python(3.6)中的microsoftfaceapi来比较两个面,使用它们的faceid或facelandmarks?如果是,请举例说明如何使用。非常感谢你。在


Tags: 编程新手faceidfacelandmarksmicrosoftfaceapi
1条回答
网友
1楼 · 发布于 2024-04-20 15:29:27

如果您想知道两个图像是否来自同一个人,可以为每个图像调用detect,然后调用verify。您可以像这样使用cognitive_face包:

import cognitive_face as CF

key = 'YOUR_KEY_HERE'  # Replace with a valid Subscription Key here.
CF.Key.set(key)

base_url = 'https://westus.api.cognitive.microsoft.com/face/v1.0/'  # Replace with your regional Base URL
CF.BaseUrl.set(base_url)

img_urls = [
    'https://images-na.ssl-images-amazon.com/images/M/MV5BMTczNzE3Njk4MV5BMl5BanBnXkFtZTcwOTU1ODk5NQ@@._V1_UY317_CR7,0,214,317_AL_.jpg',
    'https://images-na.ssl-images-amazon.com/images/M/MV5BMzIwMDgzMTE5M15BMl5BanBnXkFtZTcwNTg4OTgwOA@@._V1_UY317_CR15,0,214,317_AL_.jpg' ]

faces = [CF.face.detect(img_url) for img_url in img_urls]

# Assume that each URL has at least one face, and that you're comparing the first face in each URL
# If not, adjust the indices accordingly.
similarity = CF.face.verify(faces[0][0]['faceId'], faces[1][0]['faceId'])
print similarity

相关问题 更多 >