从文件夹返回图像到烧瓶

时间:2019-03-31 13:09:00

标签: python flask

我在一个文件夹中有几张图像,我想上传到我的烧瓶应用程序。

上传时,我会看到一张破碎的图像,而只是一张要上传的图像,而不是全部10张。

我制作了一个包含

的image2.html页面

并将标签包含在我的interface.html

for i in range(1):
    path = "/Users/devops/Desktop/Adversarial_Example_Project/static"

    random = np.random.random([200, 200, 3])
    #random[0:, 0:,0:]= 0
    random[ 150:200, 170:220, :]= [0.5,0.1,0.5]
    random[ 200:400, 170:220, :]= [0.1,0.3,0.6]
    random_image_location = path + '/adv/noise_00' + str(i) + '.jpg'
    imsave(random_image_location, random)

    clean_image = Image.open(image_path)
    noise_image = Image.open(random_image_location)

    clean_image = changeImageSize(200, 200, clean_image)
    noise_image = changeImageSize(200, 200, noise_image)


    clean_image = clean_image.convert("RGBA")
    noise_image = noise_image.convert("RGBA")
    adv_images = []

    for alpha_val in np.arange(0, 1, 0.1):
        percent =round( alpha_val *100)
        Advimg = Image.blend(clean_image, noise_image, alpha=alpha_val)
        adv_img_path = path + '/adv/adv' + str(i) + '-' + str(percent) + ".PNG"
        Advimg.save(adv_img_path, "PNG")
        adv_images.append(adv_img_path)

        print("Noise applied by " +str(percent)+  "% to images")

我想在我的flask Web应用程序上可视化保存在adv_images中的所有图像。

谢谢

1 个答案:

答案 0 :(得分:0)

尝试用烧瓶中的url_for模板代替image.open:

{{ url_for(‘<yourimagefolder>’, filename=‘<yourimgname>’ }}