I’m using the following code to develop a list of the images in a specific folder. I’d like to then use the list to display the images and be able to go back or forward as needed. Is there any way to iterate thru the file list to accomplish this?
import os
import sys
import numpy as np
import cv2
file_list=[]
#Path for MacOS
path = '/Users/username/Documents/Images/'
files = os.listdir(path)
for file in files:
if file.endswith(('.jpg', '.png', 'tiff')):
img_path = path + file
file_list.append(file)
img = cv2.imread(img_path)
cv2.imshow('My Image',img)
cv2.moveWindow('My Image',400,5)
k = cv2.waitKey(0)
if k%256 == 27: # ESC pressed
file_list = sorted(file_list)
print(file_list)
print("Escape hit, closing...")
cv2.destroyAllWindows()
sys.exit()
I’ve tried to research this but the examples I’ve found only allow the forward direction, i.e., no apparent way to go back using an index. Is it possible to do this using Python / OpenCV ?
Thank you for any assistance on this.