当使用PIL.Image读取图像时,若是直接使用numpy.array()转换会出现错误:app
lst = list() for file_name in os.listdir(dir_image): image = PIL.Image.open(file_name) lst.append(image) arr = numpy.array(lst)
此时,上述最后一行在执行时会出现错误:code
TypeError: int() argument must be a string, a bytes-like object or a number, not 'Image'
解决办法以下:对象
lst = list() for file_name in os.listdir(dir_image): image = PIL.Image.open(file_name) lst.append(np.array(image)) arr = numpy.array(lst)
即,在list中的元素都已转化为numpy.array,而非直接的Image对象。string