Face++ Face_Recognition API 的简单使用

face.JPG

Face++ API 地址点击可以查看api文档 ,注册、环境搭建什么的就不说了。

把key、secret换成你自己的就OK啦

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import requests
from json import JSONDecoder
import time
http_url='https://api-cn.faceplusplus.com/facepp/v3/detect'
key = "your key"
secret = "your secret"
filepath = r"gaoyuanyuan.jpg"
#API说明二进制文件,需要用 post multipart/form-data 的方式上传
data = {"api_key": key, "api_secret": secret, "return_landmark": "1" , "return_attributes":"gender,ethnicity,age,smiling,emotion,beauty"}
files = {"image_file": open(filepath, "rb")}
response = requests.post(http_url, data=data ,files=files)
req_con = response.content.decode('utf-8')
req_dict = JSONDecoder().decode(req_con)
print("本次请求ID:" ,req_dict["request_id"])
print("---------------------------------------------------")
print("姓名:高圆圆")
print("年龄:",req_dict["faces"][0]["attributes"]["age"]["value"])
print("性别:",req_dict["faces"][0]["attributes"]["gender"]["value"])
print("人种:",req_dict["faces"][0]["attributes"]["ethnicity"]["value"])
print("男性认为的此人脸颜值分数:",req_dict["faces"][0]["attributes"]["beauty"]["male_score"])
print("女性认为的此人脸颜值分数:",req_dict["faces"][0]["attributes"]["beauty"]["female_score"])
print("面部表情指数:",req_dict["faces"][0]["attributes"]["emotion"])
#print(req_dict["faces"][0]["attributes"])
gaoyuanyuan.JPG zhuyin.JPG
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import requests
from json import JSONDecoder
#API账号相关信息,自己在自己的开发者中心查
http_url='https://api-cn.faceplusplus.com/facepp/v3/compare'
key = "your key"
secret = "your secret"
#需要compare本地图片路径
image1 = r"dahan.jpg"
image2 = r"minguo.jpg"
#API说明二进制文件,需要用 post multipart/form-data 的方式上传
data = {"api_key": key, "api_secret": secret, "return_landmark": "2"}
files = {"image_file1": open(image1, "rb"),"image_file2": open(image2, "rb")}
response = requests.post(http_url, data=data, files=files)
req_con = response.content.decode('utf-8')
req_dict = JSONDecoder().decode(req_con)
#输出响应的所有信息
#print(req_dict)
#输出两张照片的置信度0-100之间,数值越大说明两张脸越像
print("两张照片的置信度0-100之间,数值越大说明两张脸越像")
print("___________________________________________________")
print("大韩和民国之间的置信度为:",req_dict["confidence"])
dahanminguowansui.JPG

你也可以在控制台查看你的使用情况

face_contrl.JPG

仅限娱乐,哈哈

Powered by Hexo and Hexo-theme-hiker

Copyright © 2013 - 2020 卖假货的学长 All Rights Reserved.

访客数 : | 访问量 :