使用Face ++进行人脸比较

时间:2019-05-08 08:27:07

标签: python

我正在使用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)

2 个答案:

答案 0 :(得分:0)

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

static

输出:

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)

答案 1 :(得分:0)

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