gpt4 book ai didi

python - 使用 Face++ 进行人脸比较

转载 作者:太空宇宙 更新时间:2023-11-03 20:55:50 25 4
gpt4 key购买 nike

我正在Python中使用facepplib库编写用于面部比较的代码,函数face_comparing(app)采用图像url进行比较。我有一些图像存储在本地磁盘中,我想在其中工作。我不知道如何将本地目录转换为网址。当我给出本地目录的路径时,它显示“错误:从 URL 下载图像失败。图像 URL 错误或无效。”

from __future__ import print_function, unicode_literals

import json

from facepplib import FacePP, exceptions

face_detection=""
faceset_initialize=""
face_search=""
face_landmarks=""
dense_facial_landmarks=""
face_attributes=""
beauty_score_and_emotion_recognition=""
def face_comparing(app):
"""
Compare two faces and decide whether they are from the same person.
"""
print('[Face Comparing]')

img_url1 = 'http://192.168.100.15/moazzam.jpg'
img_url2 = 'https://media.wmagazine.com/photos/5a6a18f56c29fa0b4cf8e5a4/4:3/w_1536/tom-cruise-joins-instagram.jpg'
cmp_ = app.compare.get(image_url1=img_url1,
image_url2=img_url2)

print('image1', '=', cmp_.image1)
print('image2', '=', cmp_.image2)

print('thresholds', '=', json.dumps(cmp_.thresholds, indent=4))
print('confidence', '=', cmp_.confidence)
if __name__ == '__main__':

api_key ='xQLsTmMyqp1L2MIt7M3l0h-cQiy0Dwhl'
api_secret ='TyBSGw8NBEP9Tbhv_JbQM18mIlorY6-D'

try:
app_ = FacePP(api_key=api_key, api_secret=api_secret)
funcs = [
face_detection,
face_comparing,
faceset_initialize,
face_search,
face_landmarks,
dense_facial_landmarks,
face_attributes,
beauty_score_and_emotion_recognition
]
face_comparing(app_)


except exceptions.BaseFacePPError as e:
print('Error:', e)

最佳答案

只需更改 img_url1 和 img_url2 处的 url 路径,代码就可以正常运行。见下文。

from __future__ import print_function, unicode_literals

import json

from facepplib import FacePP, exceptions

face_detection=""
faceset_initialize=""
face_search=""
face_landmarks=""
dense_facial_landmarks=""
face_attributes=""
beauty_score_and_emotion_recognition=""
def face_comparing(app):
"""
Compare two faces and decide whether they are from the same person.
"""
print('[Face Comparing]')

img_url1 = 'https://urbanasian.com/wp-content/uploads/2017/11/Aamir-Khan.jpg'
img_url2 = 'https://i2.cinestaan.com/image-bank/1500-1500/126001-127000/126991.jpg'

cmp_ = app.compare.get(image_url1=img_url1,image_url2=img_url2)

print('image1', '=', cmp_.image1)
print('image2', '=', cmp_.image2)

print('thresholds', '=', json.dumps(cmp_.thresholds, indent=4))
print('confidence', '=', cmp_.confidence)
if __name__ == '__main__':

api_key ='xQLsTmMyqp1L2MIt7M3l0h-cQiy0Dwhl'
api_secret ='TyBSGw8NBEP9Tbhv_JbQM18mIlorY6-D'

try:
app_ = FacePP(api_key=api_key, api_secret=api_secret)
funcs = [
face_detection,
face_comparing,
faceset_initialize,
face_search,
face_landmarks,
dense_facial_landmarks,
face_attributes,
beauty_score_and_emotion_recognition
]
face_comparing(app_)


except exceptions.BaseFacePPError as e:
print('Error:', e)

输出:

[Face Comparing]
image1 = https://urbanasian.com/wp-content/uploads/2017/11/Aamir-Khan.jpg
image2 = https://i2.cinestaan.com/image-bank/1500-1500/126001-127000/126991.jpg
thresholds = {
"1e-3": 62.327,
"1e-5": 73.975,
"1e-4": 69.101
}
confidence = 92.107

关于python - 使用 Face++ 进行人脸比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56036510/

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