简体   繁体   English

使用 Pillow 保存图像而不覆盖已保存的图像

[英]Save images using Pillow without overwriting already saved images

I want to save around 12000 images generated from a particular code.我想保存从特定代码生成的大约 12000 张图像。 I will be able to save these images only using my Project VPN which keeps disconnecting some times and then the entire process of saving takes place by overwriting already saved images and taking again a lot of time.我将只能使用我的 Project VPN 保存这些图像,该 VPN 会不断断开连接,然后通过覆盖已保存的图像并再次花费大量时间来完成整个保存过程。

How do I avoid this?我如何避免这种情况?

from PIL import Image
dirc = os.path.join(r"C:\\", "DATASET", "Images", f"{measurename}")
if not os.path.exists(dirc):
    os.makedirs(dirc)
    gray_image_cropped.save(os.path.join(dirc, f"{id}_seg{obj}.tif"))

Check whether the file exists:检查文件是否存在:

from PIL import Image
dirc = os.path.join(r"C:\\", "DATASET", "Images", f"{measurename}")

if not os.path.exists(dirc):
    os.makedirs(dirc)

outfile = os.path.join(dirc, f"{id}_seg{obj}.tif"

if not os.path.exists(outfile):
    gray_image_cropped.save(outfile))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM