Last active
January 19, 2017 12:05
-
-
Save romanschejbal/2fa1dc3fed94f53963fb8b63f02bb102 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
import os, sys, cv2, numpy | |
path = sys.argv[1] | |
filename = sys.argv[2] | |
blendCount = int(sys.argv[3]) | |
files = os.listdir(path) | |
files = sorted(files) | |
previousImage = Image.open(path + '/' + files[0]) | |
height, width, layers = numpy.array(previousImage).shape | |
video = cv2.VideoWriter(filename, -1, 30, (width, height)) | |
for imageFilename in files: | |
image = Image.open(path + '/' + imageFilename) | |
if files[0] != imageFilename: | |
for i in range(1, blendCount + 1): | |
print 'Blending ' + str(i / float(blendCount + 1)) | |
blendedImage = Image.blend(previousImage, image, i / float(blendCount + 1)) | |
video.write(cv2.cvtColor(numpy.array(blendedImage), cv2.COLOR_RGB2BGR)) | |
print 'Adding ' + imageFilename | |
video.write(cv2.cvtColor(numpy.array(image), cv2.COLOR_RGB2BGR)) | |
previousImage = image | |
video.release() | |
print width | |
print height |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
timelapse.py ~/Downloads/directory-with-photos-only destination-file.mp4 1