软件openCV基于openCV的图片查看器HolioFox2023-12-062024-09-231234567891011121314151617181920212223242526272829303132333435363738import osimport cv2# 图片文件夹路径folder_path = 'D:/Users/image'# 获取文件夹中的所有图片文件image_files = [os.path.join(folder_path, file) for file in os.listdir(folder_path) if file.lower().endswith(('.png', '.jpg', '.jpeg'))]# 创建一个图片显示窗口cv2.namedWindow('Image Viewer', cv2.WINDOW_NORMAL)# 初始化图片索引current_index = 0total_images = len(image_files)while True: # 读取当前索引处的图片 image_path = image_files[current_index] image = cv2.imread(image_path) # 显示图片 cv2.imshow('Image Viewer', image) # 等待用户按键 key = cv2.waitKey(0) # 根据按键进行操作 if key == ord('a'): # 按下a键退出 break elif key == ord('s'): # 按下s键显示下一张图片 current_index = (current_index + 1) % total_images elif key == ord('d'): # 按下d键显示上一张图片 current_index = (current_index - 1) % total_images# 关闭窗口cv2.destroyAllWindows()