[使用Face ++进行面部比较

问题描述 投票:1回答:2

[我正在使用facepplib库在python中编写用于面部比较的代码,功能face_comparing(app)需要使用图像url进行比较。我有一些要存储在本地磁盘上的图像。我不知道如何将本地目录转换为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)
python
2个回答
0
投票

只需更改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

0
投票

如果要比较本地驱动器映像,请尝试将网站上本地驱动器映像的URL链接作为https://postimages.org/,并使用与本地驱动器映像的url链接相同的程序来获得结果。我使用了相同的工具,并且可以正常工作。将图像链接显示为https://prnt.sc/pi9duy,它显示了本地驱动器图像的URL链接。

© www.soinside.com 2019 - 2024. All rights reserved.