我有用于从照片中检索参数的代码。我需要将其放入循环中,以便从文件夹中加载我的所有照片,并在此处以Python的输入代码将其写下来
import requests
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'
}
img_path = 'C:\\Users\\Pifko\\Desktop\\bakalarka\\subject13session2_Moment5up.jpg'
img_data = open(img_path, 'rb').read()
def post_image(img_data):
response = requests.post(BASE_URL, params=parameters,
headers=headers, data=img_data)
try:
return response.json()
except:
return None
print(post_image(img_data))
答案 0 :(得分:0)
我想你想要stage('Build')
{
.....
steps {
checkout scm
powershell "./build.ps1 -Target CIBuild -configuration ${params.BuildConfiguration} -Verbosity ${params.Verbosity} --settings_skipverification=${params.CAKE_SKIP_VERIFICATION}"
}
}
def runTests(target) {
unstash 'Scripts'
unstash 'Database'
unstash 'TestData'
unstash 'Config'
unstash 'FunctionalTests'
dir('build/scripts') {
timeout(time: 60, unit: 'MINUTES') {
execCakeCI("UnzipArtifacts")
execCakeCI(target)
}
}
}
def execCakeCI(target) {
echo "Running CAKECI [${target}]"
powershell "./build.ps1 -Target ${target} -Verbosity ${params.Verbosity} --settings_skipverification=${params.CAKE_SKIP_VERIFICATION}"
}
stage('Test')
{
runTests("RunFunctionalTests")
}
答案 1 :(得分:0)
您可以使用以下扩展名获取所有带有'.jpg'扩展名的文件的列表:
import glob, os
os.chdir("/mydir")
for file in glob.glob("*.jpg"):
print(file)
您可以将代码放入函数中,然后为每个文件而不是print语句调用它。