enter code here
from PIL import Image
from os import listdir
from os.path import splitext
import cv2
target_directory = r"E:\pre\png"
target = '.jpg'
jpg_folder_path = r"E:\pre\jpeg"
for file in listdir(target_directory):
filename, extension = splitext(file)
try:
if extension not in ['.py', target]:
im = Image.open(filename + extension)
#im.save((os.path.join(jpg_folder_path, im))filename + target)
cv2.imwrite(os.path.join(jpg_folder_path , filename + target), im)
except OSError:
print('Cannot convert %s' % file)
ВЫХОД
Невозможно преобразовать 000c1434d8d7.png
Невозможно преобразовать 00a8624548a9.png ..