python读取图片自动旋转的问题解决
一、安装包
安装所需的安装包
pip install pillow image-to-numpy
二、脚本代码
在自己的Python代码中加入这样几句
import os
import matplotlib.pyplot as plt
import image_to_numpy# 定义文件夹路径
folder_path = r"D:/1/SAM/sam-main/data/image/images(1)"# 获取文件夹中所有.jpg文件
jpg_files = [f for f in os.listdir(folder_path) if f.endswith('.jpg')]# 遍历所有.jpg文件并加载显示
for file_name in jpg_files:# 构造完整的文件路径img_path = os.path.join(folder_path, file_name)# 加载图像img = image_to_numpy.load_image_file(img_path)# 显示图像plt.imshow(img)plt.title(file_name) # 显示文件名作为标题plt.show()