Face Plus Plus Python API 更改参数

# -*- coding: utf-8 -*-

import urllib2

import urllib

import time

http_url = 'https://api-us.faceplusplus.com/facepp/v3/detect'

key = ""

secret = ""

filepath = r"iop.jpg"

boundary = '----------%s' % hex(int(time.time() * 1000))

data = []

data.append('--%s' % boundary)

data.append('Content-Disposition: form-data; name="%s"\r\n' % 'api_key')

data.append(key)

data.append('--%s' % boundary)

data.append('Content-Disposition: form-data; name="%s"\r\n' % 'api_secret')

data.append(secret)

data.append('--%s' % boundary)

fr=open(filepath,'rb')

data.append('Content-Disposition: form-data; name="%s"; filename="co33.jpg"' % 'image_file')

data.append('Content-Type: %s\r\n' % 'application/octet-stream')

data.append(fr.read())

fr.close()

data.append('--%s--\r\n' % boundary)


http_body='\r\n'.join(data)

#buld http request

req=urllib2.Request(http_url)

#header

req.add_header('Content-Type', 'multipart/form-data; boundary=%s' % boundary)

req.add_data(http_body)

try:

    #post data to server

    resp = urllib2.urlopen(req, timeout=5)

    #get response

    qrcont=resp.read()

    print qrcont


except urllib2.HTTPError as e:

    print e.read()

我正在尝试更改人脸识别 API 的参数,但我无法这样做。我想改变代码


def detect_image(img_path):

    endpoint = 'https://api-us.faceplusplus.com'

    img_file = base64.encodestring(open(img_path, 'rb').read())

    try:

        response = requests.post(

            endpoint + '/facepp/v3/detect',

            {

                'api_key': API_KEY,

                'api_secret': API_SECRET,

                # 'image_url': img_url,

                'image_base64': img_file,

                'return_landmark': 1,

                'return_attributes': 'headpose,eyestatus,facequality,mouthstatus,eyegaze'

            }

        )

        # 5秒スリープ

        time.sleep(5) 

因为我想添加更多参数,以便我获得的信息丰富。我该怎么做呢?现在我只得到人脸和 face_token 的坐标。


繁华开满天机
浏览 114回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python