face++ API接口调用
人脸识别
首先我想描述一下,在学校的时候一直好奇人脸识别与人脸检测这个技术,之后做了很多实验,曾经使用过很多简单的算法来做人脸相似度对比,比如:夹角余弦算法、判断两个矩阵之间对应位置元素相同来做统计、直方图比对、欧氏距离、绝对值距离等等很多这种低级的实验我都做过,一次次的识别让我感到万分难过。之后我不在最求这种算法的研究了,改成了看别人如何实现的,你也实现出来就好。很多人说这是it从业者的征兆,这样我彻底相信了,因为作为一个it开发的从业工作者,不能什么东西都需要自己开发,公司的要求是尽快的把项目赶出来,才能到达利益最大化。下面我为大家带来我在学校一直实验的人脸识别实现吧。当然我是在调用别人的接口。
1、导入所需要的包
import requests
from json import JSONDecoder
import cv2
导包
2、定义请求返回数据画出人脸
def drawFace(face_rectangle,img):
width = face_rectangle['width']
top = face_rectangle['top']
left = face_rectangle['left']
height = face_rectangle['height']
start = (left, top)
end = (left + width, top + height)
color = (55, 255, 155)
thickness = 3
cv2.rectangle(img, start, end, color, thickness)
定义函数
3、准备好post请求的地址、key、password。
compare_url = "https://api-cn.faceplusplus.com/facepp/v3/compare"
key = "5Ut_EUtu3dG8Q60UBQdj8_LICgc4KByR"
secret = "cWXtsKOMx62m8zHUx810MG-0oGoOnhSO" faceId1 = "img_test/tong1.jpg" # 图片地址
faceId2 = "img_test/tong2.jpg" # 图片地址 data = {"api_key": key, "api_secret": secret}
files = {"image_file1": open(faceId1, "rb"), "image_file2": open(faceId2, "rb")}
response = requests.post(compare_url, data=data, files=files)
发送请求
4、对http返回数据进行转换提取
req_con = response.content.decode('utf-8')
req_dict = JSONDecoder().decode(req_con) print(req_dict) #置信度,越高说明越像
confindence = req_dict['confidence']
print(confindence) #将人脸框出来
face_rectangle_1 = req_dict['faces1'][0]['face_rectangle']
# print(face_rectangle_1)
face_rectangle_2 = req_dict['faces2'][0]['face_rectangle']
5、画出检测对比的人脸
img1 = cv2.imread(faceId1)
img2 = cv2.imread(faceId2) if confindence>=80:
drawFace(face_rectangle_1,img1)
drawFace(face_rectangle_2,img2) #图片过大,调整下大小
img1 = cv2.resize(img1,(500,500))
img2 = cv2.resize(img2,(500,500)) cv2.imshow("img1",img1)
cv2.imshow("img2",img2) cv2.waitKey(0)
cv2.destroyAllWindows()
6、下面是完整代码:
# coding:utf-8
import requests
from json import JSONDecoder
import cv2 def drawFace(face_rectangle,img):
width = face_rectangle['width']
top = face_rectangle['top']
left = face_rectangle['left']
height = face_rectangle['height']
start = (left, top)
end = (left + width, top + height)
color = (55, 255, 155)
thickness = 3
cv2.rectangle(img, start, end, color, thickness) compare_url = "https://api-cn.faceplusplus.com/facepp/v3/compare"
key = "5Ut_EUtu3dG8Q60UBQdj8_LICgc4KByR"
secret = "cWXtsKOMx62m8zHUx810MG-0oGoOnhSO" faceId1 = "img_test/tong1.jpg" # 图片地址
faceId2 = "img_test/tong2.jpg" # 图片地址 data = {"api_key": key, "api_secret": secret}
files = {"image_file1": open(faceId1, "rb"), "image_file2": open(faceId2, "rb")}
response = requests.post(compare_url, data=data, files=files) req_con = response.content.decode('utf-8')
req_dict = JSONDecoder().decode(req_con) print(req_dict) #置信度,越高说明越像
confindence = req_dict['confidence']
print(confindence) #将人脸框出来
face_rectangle_1 = req_dict['faces1'][0]['face_rectangle']
# print(face_rectangle_1)
face_rectangle_2 = req_dict['faces2'][0]['face_rectangle'] img1 = cv2.imread(faceId1)
img2 = cv2.imread(faceId2) if confindence>=80:
drawFace(face_rectangle_1,img1)
drawFace(face_rectangle_2,img2) #图片过大,调整下大小
img1 = cv2.resize(img1,(500,500))
img2 = cv2.resize(img2,(500,500)) cv2.imshow("img1",img1)
cv2.imshow("img2",img2) cv2.waitKey(0)
cv2.destroyAllWindows()
face++ API接口调用的更多相关文章
- 【redis】redis实现API接口调用调用次数的限制
redis实现API接口调用调用次数的限制 参考地址:https://bbs.csdn.net/topics/391856106?page=1 参考地址:https://www.cnblogs.com ...
- [转载]android常用的API接口调用
原文地址:android常用的API接口调用作者:宋耀 显示网页: Uri uri = Uri.parse("http://www.google.com"); In ...
- Nginx api接口调用配置
1 # Nginx api接口调用配置 2 3 # 什么是跨域同源? 4 # 同源策略:协议(http.https.wss--)+域名+端口=一个完整的网站 5 # 跨域:当前所在的网站post(ge ...
- 新浪网易淘宝等IP地区信息查询开放API接口调用方法
通过IP地址获取对应的地区信息通常有两种方法:1)自己写程序,解析IP对应的地区信息,需要数据库.2)根据第三方提供的API查询获取地区信息. 第一种方法,参见文本<通过纯真IP数据库获取IP地 ...
- ajax跨域实现api 接口调用
背景: 想实现跨域去调用接口, 然后同时支持下次调用,能够带cookie信息过来,同时支持来自多个源头的域名的跨域调用. 1.这样支持来自所有域名的跨域调用: 不支持跨域是,浏览器报错: 在api接口 ...
- JAVA的免费天气api接口调用示例
step1:选择本文所示例的接口"免费天气api" url:https://www.juhe.cn/docs/api/id/39/aid/87 step2:每个接口都需要传入一个参 ...
- java web api接口调用
Web Services 被W3C进行了标准化定义. Web Services 发布到网上,可以公布到某个全局注册表,自动提供服务URL,服务描述.接口调用要求.参数说明以及返回值说明.比如中国气象局 ...
- 小程序API接口调用
1.在config.js中写入api接口及appkey 2.在HTTP.js中引入config.js,然后新建HTTP.js,在里进行wx.request的封装. 定义一个HTTP的类,来类里定义 ...
- .Net RabbitMQ实战指南——HTTP API接口调用
RabbitMQ Management插件还提供了基于RESTful风格的HTTP API接口来方便调用.一共涉及4种HTTP方法:GET.PUT.DELETE和POST.GET方法一般用来获取如集群 ...
- Restful API接口调用的方法总结
restful 接口调用的方法 https://www.cnblogs.com/taozhiye/p/6704659.html http://www.jb51.net/article/120589.h ...
随机推荐
- Mac上配置Cocos2d-x开发环境(多平台:Android/iOS)
下载以下资源: Cocos2d-x (http://www.cocos2d-x.org) Android NDK(http://developer.android.com/tools/sdk/ndk/ ...
- Vue学习(四):条件渲染
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 再见NullPointerException。在Kotlin里null的处理(KAD 19)
作者:Antonio Leiva 时间:Apr 4, 2017 原文链接:https://antonioleiva.com/nullity-kotlin/ 关于Kotlin最重要的部分之一:无效处理, ...
- Python简要标准库(5)
hashlib Python的hashlib提供了常见的摘要算法,如MD5,SHA1等等. 基本的生成MD密匙的函数 import hashlib md5 = hashlib.md5() md5.up ...
- Gitlab自动触发Jenkins构建项目
Gitlab自动触发Jenkins构建项目 一.前提 Gitlab已安装配置好. Jenkins已安装Gitlab plugin. 二.配置jenkins中Job 1.勾选触发器下的gitlab触发器 ...
- python完成简单购物功能
# # -*- coding: utf8 -*- # # Author:wxq # # date:2017/11/13 # # python 3.6 # 创建一个商品列表: product_lis = ...
- 网络流——poj1273(入门)
题目链接:排水沟 题意:现有n个排水沟和m个点(其中1是源点,m是汇点),给定n个排水沟所连接的点,求从源点到汇点的最大流量. [EK解法] #include <algorithm> #i ...
- Week8 Teamework from Z.XML-Z.XML游戏功能说明
我们小组的游戏终于新鲜出炉了,好开心~ 快来看看有什么功能吧. 游戏目标::=打倒最多的敌人,获得积分,放松心情,获取快乐. 游戏菜单::= 关于+设置+帮助+积分榜+开始游戏吧 (截图还在路上..) ...
- poi解析excel出现格式不正确
后缀为xlsx的excel做系统导入时出现bug: Strict OOXML isn't currently supported, please see bug #57699 为了同时兼容03.07及 ...
- perf原理再看
vim ./arch/x86/kernel/hw_breakpoint.c perf如何控制采样的频率 perf采样不同的事件,得到的不是一样 cycles: 向PMU中增加不同的函数,增加不同 使用 ...