一. 准备工作
1. 此程序使用的是 Face++ 的API,所以需要去Face++官网注册账号:
https://www.faceplusplus.com.cn/
2. 创建应用,获取 key 和 secret
3. 下载 simplejson 模块 ,使用pip就可以下载了
pip install simplejson
二. 程序思路
1. 使用 decect 接口,获取人脸关键点
接口详细文档:
https://console.faceplusplus.com.cn/documents/4888373
* return_landmark 参数 不能为 0 不然不会返回人脸关键点
return_landmark | Int | 是否检测并返回人脸关键点。合法值为:
注:本参数默认值为 0 |
核心代码:
def find_face(imgpath):
print("finding")
http_url = 'https://api-cn.faceplusplus.com/facepp/v3/detect'
data = {"api_key": key, "api_secret": secret, "image_url": imgpath, "return_landmark": 1}
files = {"image_file": open(imgpath, "rb")}
req_con = response.content.decode('utf-8')
response = requests.post(http_url, data=data, files=files) req_dict = JSONDecoder().decode(req_con)
faces = this_json2['faces']
this_json = simplejson.dumps(req_dict) this_json2 = simplejson.loads(this_json) list0 = faces[0] rectangle = list0['face_rectangle']
return rectangle
# print(rectangle)