Skip to content

Instantly share code, notes, and snippets.

Last active Apr 15, 2018
What would you like to do?
Fixed syntax and added documentation for the timelapse script from
#!/usr/bin/env python
import numpy as np
import cv2
from skimage.measure import compare_ssim as ssim
import time
# Pick a source - either a file or a (exiting) device
cap = cv2.VideoCapture('/dev/video0')
ret,previous =
best_frame = previous
number = 50
file = 0
i = 0
best_s = 0
i += 1
ret, frame =
s = ssim(frame, previous, multichannel=True)
if(s > best_s):
best_s = s
best_frame = frame
cv2.imwrite('folder/%04d.png' % file,best_frame)
file += 1
previous = best_frame
# Installing conda through Berryconda (
chmod +x
./ -b -f
# Install the prerequisites for the script above
conda install -c menpo opencv ffmpeg scikit-image
# Run the script as long as you have to
# Rendering the timelapse video
ffmpeg -r 1 -i folder/%04d.png -c:v libx264 -vf "fps=50,setpts=0.25*PTS" -pix_fmt yuv420p out.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment