美文网首页人工智能
Python程序体验Face++人脸检测

Python程序体验Face++人脸检测

作者: geekAppke | 来源:发表于2019-04-24 14:46 被阅读0次

注册Face++,并创建API Key

  1. Face++控制台
  2. Face++ - 文档中心
import requests
import json
from PIL import Image, ImageDraw
# https://console.faceplusplus.com.cn/documents/4888373

http_url = 'https://api-cn.faceplusplus.com/facepp/v3/detect'
key = '3Q0mGshLAwH_HrGj7fL2L9v9OboJqIMs'
secret = 'fVrO8-TkqUeum8w0IVNjTokqP6vkP5xL1'
filepath = 'allok3.jpg'

data = {'api_key':key, 'api_secret':secret, 'return_landmark':'1'}
files = {'image_file': open(filepath, 'rb')}

resposen = requests.post(http_url, data=data, files=files)
resp_dict = resposen.json()
print(resp_dict)

if 'error_message' in resp_dict:
    print('受限制')
else:
    faces = resp_dict['faces']
    faceName = len(faces)
    im = Image.open(filepath)
    draw = ImageDraw.Draw(im)

    for i in range(faceName):
        face_rectangle = faces[i]['face_rectangle']
        width = face_rectangle['width']
        top = face_rectangle['top']
        left = face_rectangle['left']
        height = face_rectangle['height']
        start = (left, top)
        end = (left+width, top+height)

        draw.rectangle([start, end], outline='red')
    im.show()

相关文章

网友评论

    本文标题:Python程序体验Face++人脸检测

    本文链接:https://www.haomeiwen.com/subject/rvrggqtx.html