First, here is the code I have:
import cv2
import os,errno
from os.path import expanduser
from datetime import datetime
import glob
import numpy as np
##################### Creating folder & subfolders #####################
b_temp_folder = 'b_temp'
c_path = os.path.join('C:\\', b_temp_folder)
try:
c_dir = os.mkdir(c_path)
except OSError as e:
if e.errno != errno.EEXIST:
raise
now = datetime.now()
id_folder = now.strftime('%Y%m%d-%H%M%S-%f')
b_path = os.path.join('C:\\b_temp\\',id_folder)
b_dir = os.mkdir(b_path)
##################### Images processing #####################
for img in glob.glob('C:\\Users\\User\\Desktop\\Images\\*.tif'):
cv_img = cv2.imread(img)
cv_show = cv2.imshow('img',cv_img)
cv2.waitKey(0)
In the first part, some folders are being created. First a folder in 'C:\' and inside it, a folder with datetime as name. These last are created everytime the code is executed, so they are unique (sorted by milliseconds..).
Running the for
will show all images at once.
Here is the question: how can I sent every image to it's unique folder ? I mean, the first image to the first unique folder, and so on..
Going by logic, folders are being created every time all the code run (one folder at the time). The images, instead, are iterated all in the same instance. How can I modify this ?
P.S - As you can see, I created this temp folder in the C drive. My plan was to make this code a little bit cross-platform. I tried the os.path.expanduser but it seems not working. No folder is created at all... Someone know why ?
Thanks