Skip to content

Instantly share code, notes, and snippets.

@tolleiv
Last active April 15, 2018 09:14
Show Gist options
  • Save tolleiv/996373132e3725fe02a2137836d50723 to your computer and use it in GitHub Desktop.
Save tolleiv/996373132e3725fe02a2137836d50723 to your computer and use it in GitHub Desktop.
Fixed syntax and added documentation for the timelapse script from https://reps.cc/?p=85
#!/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 = cap.read()
best_frame = previous
number = 50
file = 0
while(True):
i = 0
best_s = 0
while(i<=number):
i += 1
ret, frame = cap.read()
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
cap.release()
cv2.destroyAllWindows()
# Installing conda through Berryconda (https://github.com/jjhelmus/berryconda)
wget https://github.com/jjhelmus/berryconda/releases/download/v2.0.0/Berryconda3-2.0.0-Linux-armv7l.sh
chmod +x Berryconda3-2.0.0-Linux-armv7l.sh
./Berryconda3-2.0.0-Linux-armv7l.sh -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
berryconda3/bin/python cap.py
# 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