简体   繁体   中英

Save images using Pillow without overwriting already saved images

I want to save around 12000 images generated from a particular code. 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.

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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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