I'm trying to get data from this function:
def read_images(path, sz=None):
"""Reads the images in a given folder, resizes images on the fly if size is given.
Args:
path: Path to a folder with subfolders representing the subjects (persons).
sz: A tuple with the size Resizes
Returns:
A list [X,y]
X: The images, which is a Python list of numpy arrays.
y: The corresponding labels (the unique number of the subject, person) in a Python list.
"""
c = 0
X,y = [], []
for dirname, dirnames, filenames in os.walk(path):
for subdirname in dirnames:
subject_path = os.path.join(dirname, subdirname)
for filename in os.listdir(subject_path):
try:
im = Image.open(os.path.join(subject_path, filename))
im = im.convert("L")
# resize to given size (if given)
if (sz is not None):
im = im.resize(self.sz, Image.ANTIALIAS)
X.append(np.asarray(im, dtype=np.uint8))
y.append(c)
except IOError, (errno, strerror):
print "I/O error({0}): {1}".format(errno, strerror)
except:
print "Unexpected error:", sys.exc_info()[0]
raise
c = c+1
return [X,y]
The problem is that when I call the function
[X,y] = read_images('/Trainer')
where Trainer is the folder that have the images. Now, when I call this function, the function can't reach the folder and the values of X and y are still empty. I tried to print X and print y and both values where X=[] y=[] I tried also to do it like this
TrainerPath = "C:\Users\Eng. Aladdin Hammodi\Desktop\recognizer\Trainer"
[X,y] = read_images(TrainerPath)
but still have the same thing. What should I do?
os.listdir('C:\Users\Eng. Aladdin Hammodi\Desktop\recognizer\Trainer')?