日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python人脸对比相似度_python人脸对比

發布時間:2024/4/17 python 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python人脸对比相似度_python人脸对比 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

import sys

import ssl

from urllib import request,parse

# client_id 為官網獲取的AK, client_secret 為官網獲取的SK

#獲取token

def get_token():

client_id =API Key

client_secret =Secret Key

host = ‘https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=%s&client_secret=%s‘%(client_id,client_secret)

req = request.Request(host)

req.add_header(‘Content-Type‘, ‘application/json; charset=UTF-8‘)

response = request.urlopen(req)

#獲得請求結果

content = response.read()

#結果轉化為字符

content = bytes.decode(content)

#轉化為字典

content = eval(content[:-1])

return content[‘access_token‘]

#轉換圖片

#讀取文件內容,轉換為base64編碼

#二進制方式打開圖文件

def imgdata(file1path,file2path):

import base64

f=open(r‘%s‘ % file1path,‘rb‘)

pic1=base64.b64encode(f.read())

f.close()

f=open(r‘%s‘ % file2path,‘rb‘)

pic2=base64.b64encode(f.read())

f.close()

#將圖片信息格式化為可提交信息,這里需要注意str參數設置

params = {"images":str(pic1,‘utf-8‘) + ‘,‘ + str(pic2,‘utf-8‘)}

return params

#提交進行對比獲得結果

def img(file1path,file2path):

token = get_token()

#人臉識別API

#url = ‘https://aip.baidubce.com/rest/2.0/face/v2/detect?access_token=‘+token

#人臉對比API

url = ‘https://aip.baidubce.com/rest/2.0/face/v2/match?access_token=‘+token

params = imgdata(file1path,file2path)

#urlencode處理需提交的數據

data = parse.urlencode(params).encode(‘utf-8‘)

req = request.Request(url,data=data)

req.add_header(‘Content-Type‘, ‘application/x-www-form-urlencoded‘)

response = request.urlopen(req)

content = response.read()

content = bytes.decode(content)

content = eval(content)

print(content)

#獲得分數

score = content[‘result‘][0][‘score‘]

if score>80:

return ‘照片相似度:‘+str(score)+‘,同一個人‘

else:

return ‘照片相似度:‘+str(score)+‘,不是同一個人‘

if __name__ == ‘__main__‘:

file1path = ‘d:/ym1.jpg‘

file2path = ‘d:/ym2.jpg‘

res = img(file1path,file2path)

print(res)

總結

以上是生活随笔為你收集整理的python人脸对比相似度_python人脸对比的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。