I think it can get messy when saving images in python. If you use the following function, the image will be saved by dividing the path for each day.
Example: In the case of 2020/10/27 (10:15:30)
~/(Execution directory)/2020/10/27/10_15_30.png
from datetime import datetime
import os
def save_image(img):
#Save image
#Create folders for the year and month
nowtime = datetime.now()
savedir = os.getcwd()
if not os.path.exists(os.path.join(savedir)):
os.mkdir(os.path.join(savedir))
print("MAKE_DIR: " + savedir)
#Create year folder
savedir += datetime.now().strftime("/%Y")
if not os.path.exists(os.path.join(savedir)):
os.mkdir(os.path.join(savedir))
print("MAKE_DIR: " + savedir)
#Create a folder for the month
savedir += nowtime.strftime("/%m")
if not os.path.exists(os.path.join(savedir)):
os.mkdir(os.path.join(savedir))
print("MAKE_DIR: " + savedir)
#Generate a folder for days
savedir += nowtime.strftime("/%d")
if not os.path.exists(os.path.join(savedir)):
os.mkdir(os.path.join(savedir))
print("MAKE_DIR: " + savedir)
#time_Minutes_Generate a second folder
savefile = savedir
saveFileName = datetime.now().strftime("%H_%M_%S.png ")
saveFileName = os.path.join(savedir, saveFileName)
cv2.imwrite(saveFileName, img)
print(str(savedir) +"Saved in")
Recommended Posts