Python provides a powerful library for working with Operating System resources like file systems. We will start out with the listdir() function that lists the files in a directory.
Here is program that lists all the tub files in our mycar/data directory:
importosfromIPython.displayimportImageimage_dir="/home/arl/mycar/data/dans-msp/data/images"files=os.listdir(image_dir)# last basement image is 1710n=1710file_n=files[n]file_2=files[n+1]print(n,file_n)file_path1=image_dir+'/'+file_nfile_path2=image_dir+'/'+file_2i1=Image(file_path1)i2=Image(file_path2)print(n+1,file_2)display(i1,i2)
importosimportmatplotlib.pyplotaspltfromIPython.displayimportImagefrompathlibimportPathimage_dir="/home/arl/mycar/data/dans-msp/data/images"paths=sorted(Path(image_dir).iterdir(),key=os.path.getmtime)images=[]# just get the first 10 items in the list of imagesforpathinpaths[:10]:print(path)images.append(mpimg.imread(path))plt.figure(figsize=(20,10))columns=5fori,imageinenumerate(images):plt.subplot(len(images)/columns+1,columns,i+1)plt.imshow(image)