这是我的代码,该代码从文件夹加载图片并顺序列出其参数。我不需要解析参数,而是将其另存为csv文件。您将如何解决
import requests
import os
import csv
import time
BASE_URL = 'https://westeurope.api.cognitive.microsoft.com/face/v1.0/detect'
headers = {
'Ocp-Apim-Subscription-Key': 'd7264e9252674c9292b0d8b295cf3251',
'Content-Type': 'application/octet-stream'
}
parameters = {
'returnFaceId': 'true',
'returnFaceLandmarks': 'false',
'returnFaceAttributes': 'age,gender,emotion'
}
def post_image(img_data):
response = requests.post(BASE_URL, params=parameters,
headers=headers, data=img_data)
try:
return response.json()
except:
return None
img_path = 'C:\\Users\\Pifko\\Desktop\\bakalarka\\ffmpeg-20181107-0c6d4e7-win64-static\\ffmpeg-20181107-0c6d4e7-win64-static\\bin\\all'
files = os.listdir(img_path)
for file in files:
file = os.path.join(img_path,file)
img_data = open(file, 'rb').read()
print(post_image(img_data))
time.sleep(3)