您的位置:首页 > 编程语言 > Python开发

python调用Face++,玩坏了!

2017-07-02 18:51 267 查看
看到一句话,如果你写代码没有写诗一样的感觉,那你不适合做程序猿!

还是直接上代码吧:

import requests
from json import JSONDecoder
import cv2
import os

http_url ="https://api-cn.faceplusplus.com/facepp/v3/detect"
# your key and your secret,急用的话,可以加微信lp9628。
key ="***"
secret ="***"

filename = '/Users/liupeng/Desktop/anaconda/widerface/WIDER_train/images'
for filename1 in os.listdir(filename):
print filename1
if (filename1[0] != '.'):
filename1 = filename + '/' + filename1
for filename2 in os.listdir(filename1):
print filename2
if (filename2[0] != '.'):
filename2 = filename1 + '/' + filename2

filepath = filename2
data = {"api_key":key, "api_secret":secret, "return_landmark":"1"}
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 (len(req_dict[u'faces']))

face_num = len(req_dict[u'faces'])
frame = cv2.imread(filepath)
for i in range(face_num):
box = req_dict[u'faces'][i][u'face_rectangle']
print(box)
x, y, w, h = box[u'left'], box[u'top'],box[u'width'],box[u'height']
color = (0, 255, 0)
cv2.rectangle(frame, (x, y), (x + w, y + h), color, 2)
#显示图像
cv2.imshow("faceDetecion", frame)
c = cv2.waitKey(10)
cv2.destroyAllWindows()

如果帮到你了,请赞赏支持:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Face++ 人脸检测