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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python人脸识别pdf百度云_调用百度云接口实现人脸识别与文字识别

發(fā)布時(shí)間:2025/3/19 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python人脸识别pdf百度云_调用百度云接口实现人脸识别与文字识别 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

import requests

import base64

import json

def Get_API(): #To obtain API

#注冊(cè)百度智能云臉比對(duì)接口,獲取API密鑰和秘鑰。

#client_id = 'API Key'

client_id = '******'

#client_secret = 'Secret Key'

client_secret = '******'

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

#構(gòu)造一個(gè)函數(shù),從服務(wù)器請(qǐng)求Access_token的值,并生成人臉比較API。

response=requests.get(host) #從requests.get(url)中構(gòu)造一個(gè)url對(duì)象,該對(duì)象向服務(wù)器請(qǐng)求一個(gè)資源

access_token=eval(response.text)['access_token'] #返回請(qǐng)求的str的值,并取出“access_token”

request_url='https://aip.baidubce.com/rest/2.0/face/v3/match'

API = request_url + "?access_token=" + access_token #Stitching API

#API = "https://aip.baidubce.com/rest/2.0/face/v3/match"+"?access_token="+access_token

return API

def Image_coding(img1,img2): #Base64 encoding of the images

f=open(r'%s' % img1,'rb')

pic1=base64.b64encode(f.read()) #Image1 Base64 encoding

f.close()

f=open(r'%s' % img2,'rb')

pic2=base64.b64encode(f.read()) #Image2 Base64 encoding

f.close()

params=json.dumps([

{"image":str(pic1,"utf-8"),"image_type":'BASE64',"face_type":"LIVE"},

{"image":str(pic2,"utf-8"),"image_type":'BASE64',"face_type":"IDCARD"}])

#Add a "liveness_control" option to identify if the person in the picture is a real person

'''params=json.dumps([

{"image":str(pic1,"utf-8"),"image_type":'BASE64',"face_type":"LIVE","liveness_control": "HIGH"},

{"image":str(pic2,"utf-8"),"image_type":'BASE64',"face_type":"IDCARD","liveness_control": "HIGH"}])'''

return params #Return image parameters

def Image_contrast(img1,img2): #Analyze images and compare them

API=Get_API() #obtain API

params=Image_coding(img1,img2) #Base64 encoding of the images

content=requests.post(API,params).text #Requests for posts are sent as form forms

score=eval(content)['result']['score'] #Calculate the score

if score>=60: #Set the threshold

print('二人相似度得分為 %s, 是同一人的可能性極大'%str(score))

else:

print('二人相似度得分為 %s, 不是同一人的可能性極大'%str(score))

Image_contrast("ziqiwen.jpg","huangzz.jpg") #To run the program

總結(jié)

以上是生活随笔為你收集整理的python人脸识别pdf百度云_调用百度云接口实现人脸识别与文字识别的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。