Python 使用Face++;

Python 使用Face++;,python,Python,我正在用python编写一段代码,使用facepplib库进行面部比较,函数face_comparing(app)使用图像url进行比较。我有一些图像存储在本地磁盘上,我想在上面工作。我不知道如何将本地目录转换成url。当我给出本地目录的路径时,它会说“错误:从URL下载图像失败。图像URL错误或无效。” 只要在img_url1和img_url2处更改url路径,代码就可以正常运行。见下文 from __future__ import print_function, unicode_litera

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


只要在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

只要在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

如果要比较本地驱动器映像,请尝试从网站中找到本地驱动器映像的URL链接,并使用与本地驱动器映像的URL链接相同的程序来获得结果。我使用了相同的,并且工作正常。请参阅image link as,其中显示了本地驱动器映像的url链接。

如果要比较本地驱动器映像,请尝试从网站中找到本地驱动器映像的url链接,并使用与本地驱动器映像的url链接相同的程序来获得结果。我使用了相同的,并且工作正常。请参阅图片链接as,它显示本地驱动器图片的url链接