Skip to content

Instantly share code, notes, and snippets.

@Luxato
Created October 5, 2018 16:01
Show Gist options
  • Save Luxato/6986f1edf4c22d371793177219c6facf to your computer and use it in GitHub Desktop.
Save Luxato/6986f1edf4c22d371793177219c6facf to your computer and use it in GitHub Desktop.
Convert .png images into .jpg with python3
import xml.etree.ElementTree as ET
import pickle
import os
from os import listdir, getcwd
from os.path import join
from PIL import Image
source_dir = "C:\\Users\\Lukas\\Desktop\\KITTI dataset\\left_camera\\VOC2012\\JPEGImages"
directory = os.fsencode(source_dir)
i = 0;
for file in os.listdir(directory):
i = i + 1
filename = os.fsdecode(file)
print(i)
im = Image.open(source_dir + "\\" + filename)
rgb_im = im.convert('RGB')
filename = filename[:-4]
filename = filename + ".jpg"
rgb_im.save('C:\\Users\\Lukas\\Desktop\\jpg_images\\' + filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment