gpt4 book ai didi

python - Face Plus Plus Python API更改参数

转载 作者:行者123 更新时间:2023-11-30 09:05:49 28 4
gpt4 key购买 nike

# -*- 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的坐标。

最佳答案

使用requests库和本地存储的图像来实现Faceplusplus API。您可以根据需要选择任意数量的参数。下面的代码列出了所有参数。

import requests
import base64

def faceplusAPI(filepath):
http_url = 'https://api-us.faceplusplus.com/facepp/v3/detect'
key = "YOUR API KEY"
secret = "API SECRET"

fr = open(filepath,'rb')
img64 = base64.b64encode(fr.read())
payload = {
'api_key': key,
'api_secret': secret,
'image_base64':img64,
'return_attributes': 'age,gender,headpose,smiling,facequality,blur,eyestatus,emotion,ethnicity,beauty,mouthstatus,eyegaze,skinstatus'
}
fr.close()
try:
res = requests.post(http_url, data=payload)
return res
except Exception as e:
print('Error:')
print(e)

response = faceplusAPI("IMG_8934.JPG")

关于python - Face Plus Plus Python API更改参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52436030/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com