Skip to content

Instantly share code, notes, and snippets.

@karthick965938
Last active May 10, 2020 09:59
Show Gist options
  • Save karthick965938/aa1f4bcd55e3aa678cc3c4f370c50007 to your computer and use it in GitHub Desktop.
Save karthick965938/aa1f4bcd55e3aa678cc3c4f370c50007 to your computer and use it in GitHub Desktop.
We can using 'Download All Images' chrome extentions to get images from the google. Here i have shared some images process code
#Get images from the google
#Remove PNG images
import glob
import pathlib
for file in glob.glob('frames/*.png'):
path = pathlib.Path(file)
path.unlink()
#Rename your images files form the image directory
import os
os.getcwd()
collection = "images/cat"
for i, filename in enumerate(os.listdir(collection)):
print(filename)
os.rename(collection + "/" + filename, collection + "/cat" + str(i) + ".jpg")
#Get Images from the video
from detecto.utils import split_video
split_video('images/dog.mp4', 'images/dog/', step_size=10)
#If you have own images, need to compress the images
from PIL import Image
import os
import argparse
def rescale_images(directory, size):
for img in os.listdir(directory):
im = Image.open(directory+img)
im_resized = im.resize(size, Image.ANTIALIAS)
im_resized.save(directory+img)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Rescale images")
parser.add_argument('-d', '--directory', type=str, required=True, help='Directory containing the images')
parser.add_argument('-s', '--size', type=int, nargs=2, required=True, metavar=('width', 'height'), help='Image size')
args = parser.parse_args()
rescale_images(args.directory, args.size)
##run this command
##python your_python_file -d images/ -s 800 600
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment