提示信息:
原因:
图片被直接修改后缀导致的
解决:
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 7 11:14:41 2022
@author: 机器不学习我学习
"""
import os
from tqdm import tqdm
from PIL import Image
dir_origin_path = "VOCdevkit/VOC2007/JPEGImages"
dir_save_path = "VOCdevkit/VOC2007/JPEGImages_new"
img_names = os.listdir(dir_origin_path)
for img_name in tqdm(img_names):
if img_name.lower().endswith(('.bmp', '.dib', '.png', '.jpg', '.jpeg', '.pbm', '.pgm', '.ppm', '.tif', '.tiff')):
image_path = os.path.join(dir_origin_path, img_name)
image = Image.open(image_path)
image = image.convert('RGB')
if not os.path.exists(dir_save_path):
os.makedirs(dir_save_path)
image.save(os.path.join(dir_save_path, img_name))
参考:
https://blog.csdn.net/qq_46319397/article/details/121590134