百度云人脸识别API人脸对比
from urllib import request
import base64
import requests
import re
import json
import urllib
import os # 获取token
def get_token(client_id,client_secret):
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id='+ client_id + '&client_secret='+ client_secret + ''
headers = {'Content-Type': 'application/json; charset=UTF-8'}
res = requests.post(host, headers=headers)
access_token = re.findall('"access_token":"(.*?)"', res.text)[0]
return access_token # 打开文件夹
def geturlPath(path):
dirs = os.listdir(path)
lst = []
for dir1 in dirs:
pa = path + dir1
lst.append(pa)
return lst # 打开本地图片,并转化为base64
def open_pic2base(image):
f = open(image,'rb')
img = base64.b64encode(f.read()).decode('utf-8')
return img # 对两张图片进行对比
def check2pic(client_id,client_secret,image1,image2):
request_url = "https://aip.baidubce.com/rest/2.0/face/v3/match"
for image in image2:
a = open_pic2base(image)
b = base64.b64decode(a)
params = json.dumps(
[{"image": open_pic2base(image1), "image_type": "BASE64","quality_control": "LOW"},
{"image": a, "image_type": "BASE64","quality_control": "LOW"}]) # 调用接口
access_token = get_token(client_id, client_secret)
request_url = request_url + "?access_token=" + access_token
params = params.encode("utf-8")
request = urllib.request.Request(url=request_url, data=params)
request.add_header('Content-Type', 'application/json') response = urllib.request.urlopen(request)
content = response.read()
score = 0
if content:
result = json.loads(content.decode('utf-8'))
if result["error_code"] == 0:
score = result["result"]["score"]
if score > 75:
with open('G:/images6/'+ image.split('/')[-1],'wb') as f:
f.write(b)
f.close()
else:
errors = {}
error_msg = result["error_msg"]
errors[image.split('/')[-1]] = error_msg
print(errors)
if __name__ == '__main__':
client_id = '***************'
client_secret = '*******************'
path = r'G:/images5/' image1 = 'G:\images2\gu1.jpg'
image2 = geturlPath(path) # 将两张图片进行对比,得出相似分
check2pic(client_id,client_secret,image1,image2)
百度云人脸识别API人脸对比的更多相关文章
- 百度云人脸识别API人脸库管理
from urllib import request import base64 import requests import re import json import urllib impor ...
- 转《trackingjs+websocket+百度人脸识别API,实现人脸签到》流程
先用websocket与后台建立通讯:用trackingjs在页面调用电脑摄像头,监听人脸,发现有人脸进入屏幕了,就把图片转成base64字符串,通过websocket发送到后端:后端拿到图片,调用百 ...
- trackingjs+websocket+百度人脸识别API,实现人脸签到
在公司做了个年会的签到.抽奖系统.用java web做的,用公司的办公app扫二维码码即可签到,扫完码就在大屏幕上显示这个人的照片.之后领导让我改得高大上一点,用人脸识别来签到,就把扫二维码的步骤改成 ...
- 免费人脸识别APi
今天对应一些免费的人脸识别的api 做了一下简单的对比,觉得百度开发出来的人脸识别接口还是最符合的我的要求,简单易用,容易上手. 据说百度的一些门禁也使用上了人脸识别的功能了,功能很强大,而且能识别出 ...
- 基于node.js人脸识别之人脸对比
基于node.js人脸识别之人脸对比 Node.js简介 Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境. Node.js 使用了一个事件驱动.非阻塞式 I/O ...
- 某简单易懂的人脸识别 API 的开发环境搭建和简易教程
最近接了个人脸识别相关的项目,是基于某个非常简单易懂的人脸识别 API:face_recognition 做的.这个库接口非常傻瓜,很适合新手上手,而且可以研究其源码来学习 dlib 这个拥有更加灵活 ...
- 微信公众平台消息接口开发(24)图片识别之人脸识别API
微信公众平台开发模式 微信 公众平台 消息接口 开发模式 企业微信公众平台 图片识别 人脸识别 API 作者:方倍工作室 原文:http://www.cnblogs.com/txw1958/archi ...
- java 虹软ArcFace 2.0,java SDK使用、人脸识别-抽取人脸特征并做比对
java人脸识别 虹软ArcFace 2.0,java SDK使用.人脸识别-抽取人脸特征并做比对 虹软产品地址:http://ai.arcsoft.com.cn/product/arcface.ht ...
- Android利用百度云来识别身份证及各种证件的信息
上一篇中我已经介绍过了ocr,及google出来的tess-two的使用. 接下来我来介绍一个更方便的身份证识别系统,当然它本身也是利用ocr来识别文字的,不过它处理的更好,可以为我们提供更快,更准确 ...
随机推荐
- I2C硬件与模拟的区别
硬件I2C对应芯片上的I2C外设,有相应I2C驱动电路,其所使用的I2C管脚也是专用的,因而效率要远高于软件模拟的I2C:一般也较为稳定,但是程序较为繁琐. 硬件(固件)I2C是直接调用内部寄存器进行 ...
- Sqlserver 2014 下载
ed2k://|file|cn_sql_server_2014_enterprise_edition_x64_dvd_3932882.iso|2898847744|A33CE10CD989083D1A ...
- pwn-pwn2
环境说明 Ubuntu 16.04 pwntool IDA gdb-peda 先丢到Ubuntu看看文件的类型 64位 然后看看保护机制,发现没有保护机制 然后丢到IDA看看 F5查看伪代码 ma ...
- mysql 高级查询二
各种showshow columns from my_student;show grants for root;show aviables;show processlist;show table st ...
- getpatch
import time import os import math import sys import os,os.path,shutil import numpy as np import cv2 ...
- java自定义词典使用Hanlp
一开始按照网上的方法在配置文件加入自定义的词典不行,不知道是什么问题,这里给出链接,有兴趣的自己尝试:https://my.oschina.net/u/3793864/blog/3073171 说一下 ...
- java中的转义字符(遇到再进一步总结)
一.常见的转义字符转移字符对应的英文是escape character , 转义字符串(Escape Sequence)字母前面加上捺斜线""来表示常见的那些不能显示的ASCII字 ...
- RabbitMQ的使用(五)RabbitMQ Java Client简单生产者、消费者代码示例
pom文件: <dependencies> <dependency> <groupId>com.rabbitmq</groupId> <artif ...
- Python实现网络多人聊天室 - Windows
项目名称:多人聊天室项目结构: client.py server.py settings.py项目思路:服务端接收客户端连接,客户端发送信息给服务端,服务端将信息发送给所有客户端.项目实现:主进程负责 ...
- 用Python爬取猫眼上的top100评分电影
代码如下: # 注意encoding = 'utf-8'和ensure_ascii = False,不写的话不能输出汉字 import requests from requests.exception ...