使用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()  


猜你喜欢

转载自blog.csdn.net/weixin_39874268/article/details/79950199