图像的命名情况如下图所示,以一个字符串和数字组成,希望以1到30的顺序读入文件并以图像矩阵的形式储存在内存中以便后续处理。
使用python编程,借助os库和opencv库。
关键就是使用sort对数字重新排序。
def read_finger_directory(directory_name):
imglist = os.listdir(r"./"+directory_name)
array_of_img = [] # this if for store all of the image data
# print(imglist)
imglist.sort(key=lambda x: int(x.replace("finger", "").split('.')[0]))
# print("list_order:", imglist)
# this loop is for read each image in this foder,directory_name is the foder name with images.
for filename in imglist:
# print(filename) #just for test
# img is used to store the image data
img = cv2.imread(directory_name + "/" + filename)
# print(filename)
array_of_img.append(img)
# print(img)
# print(array_of_img)
return array_of_img