使用face++api python3.6环境下 记录

http_url =" https://api-cn.faceplusplus.com/facepp/v3/detect"
key ="your_key"
secret ="your_secret"
return_attributes="gender,age,smiling,headpose,facequality"
data = {"api_key":key, "api_secret": secret, "return_landmark":"1","return_attributes":return_attributes}
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)


face_num = len(req_dict[u'faces'])
print(face_num)
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)
    gender=req_dict[u'faces'][i][u'attributes'][u'gender'][u'value']
    cv2.putText(frame,gender,(x, y),font, 1.2, (255, 255, 255),1)
#显示图像  
cv2.imshow("faceDetecion", frame)          
c = cv2.waitKey()  


阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭