Skip to content

Instantly share code, notes, and snippets.

@hiway
Last active August 29, 2015 14:03
Show Gist options
  • Save hiway/424ced38411c10bf35bc to your computer and use it in GitHub Desktop.
Save hiway/424ced38411c10bf35bc to your computer and use it in GitHub Desktop.
Timelapse Scripts Collection (written at different times, for different devices)
#!/usr/bin/env python
import os, re
from subprocess import call, Popen, PIPE
def run(command):
print 'Running:', command
p = Popen(command, shell=True, stdout=PIPE)
lines = p.stdout.readlines()
for line in lines:
print 'Stdout :', line,
return lines
def capture(shutter=1):
c = 'gphoto2 --set-config "/main/capturesettings/exptime=%s" --capture-image' %(shutter)
sout = run(c)
firstLine = sout[0]
expr = 'New file is in location (.*?) on the camera'
comp = re.compile(expr, re.DOTALL)
path = re.findall(comp, firstLine)[0]
dir, fname = os.path.split(path)
c = 'gphoto2 --get-file %s --folder %s'%(fname, dir)
run(c)
c = 'gphoto2 --delete-file %s --folder %s'%(fname, dir)
run(c)
c = 'gphoto2 --storage-info'
run(c)
shutters = [
'0.010',
'0.020',
'0.040',
'0.080',
'0.166',
'0.333',
'0.666',
'1.250',
'2.500',
'5',
'10',
]
for shutter in shutters:
capture(shutter)
#!/usr/bin/env python
import commands
exposures = [
"1",
"10",
"50",
"150",
"300",
]
for shutter in exposures:
print commands.output("""gphoto2 --set-config "/main/capturesettings/exptime"="%s" --capture-image """ % shutter)
#! /bin/bash
self=`basename $0`
case "$ACTION" in
init)
echo "$self: INIT"
# exit 1 # non-null exit to make gphoto2 call fail
;;
start)
echo "$self: START"
;;
download)
echo "$self: DOWNLOAD to $ARGUMENT"
killall eog
eog --fullscreen ${ARGUMENT} &
;;
stop)
echo "$self: STOP"
;;
*)
echo "$self: Unknown action: $ACTION"
;;
esac
exit 0
mencoder "mf://*.jpg" -mf fps=12 -o timelapse.avi -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=800
gphoto2 --capture-image --interval 30 -F 0 --hook-script showpic.sh
#!/usr/bin/env python
## webcam.py -- Capture images from webcam -*- Python -*-
import sys
import opencv
import os
from opencv import highgui
import Image, ImageFilter
from time import localtime, strftime, sleep
camera = highgui.cvCreateCameraCapture(0)
def get_image():
return opencv.adaptors.Ipl2PIL(highgui.cvQueryFrame(camera))
def gen_file_name():
"""Generate a file name to use
"""
return strftime("%Y-%m-%d_%H:%M:%S", localtime())
def gen_dir_name():
"""Generate a directory name for the session/day
"""
return strftime("%Y-%m-%d", localtime())
if __name__ == '__main__':
try:
while True:
dir_name = gen_dir_name()
try:
os.stat(dir_name)
except:
os.mkdir(dir_name)
file_name = os.path.join(dir_name, gen_file_name() + '.jpg')
get_image().filter(ImageFilter.SHARPEN).save(file_name, 'JPEG')
sleep(60) # Sleep for a minute
except KeyboardInterrupt:
sys.exit()
from time import strftime
import e32
import camera
import appuifw
class timeLapseCamera:
def __init__(self):
# Default path to save files
# TODO: add function to browse the filesystem and save default setting.
self.path="E:\\Images\\Timelapse\\"
def capture(self, count):
# Shoot!
img = camera.take_photo()
# Take a break
e32.ao_yield()
# Let other applications use the camera in the meanwhile.
camera.release()
# Filename pattern: IMG_20080122_143612(001).jpg
now = strftime('%Y%m%d_%H%M%S')
filename = self.path + "IMG_%s(%03d)" % (now,count) + ".jpg"
# Just in case somebody forgot to make the "template" folder
# TODO: add code to automatically make it
try:
img.save(filename)
except:
appuifw.note(u"Unable to save photo. Please check if folder %s exists." %self.path, "error")
# Let the caller know where the file was saved... we want
# to display it later
return filename
def start(self, interval=10, total=10):
# Used for two things - filename count and to quit after X photos
count = 1
# Endless loop! *shiver*
while True:
count+=1 # needs no explanation, or... ?
# quit if we have the number of photos asked for.
if count >= total:
break
# Do the actual "clicking" part
filename = self.capture(count)
# Update the user about the progress of our world domination program
print "photo %03d saved at %s\n" %(count, filename)
# Too much tired... go to sleep, what else?
e32.ao_sleep(interval)
# If we have all the files we want, and user has not pressed quit
appuifw.note(u"Saved total %03d photos. Stopping." %count, "info")
def do_exit(self):
# Remind user where the files are at...
appuifw.note(u"Files saved at: " + self.path, "info")
# Pack up.
app.set_exit()
if __name__ == '__main__':
# Get timelapse parameters
# Number of seconds between each photo
interval = appuifw.query(u"Interval:", "number")
# Total photos that we want to take - either keep 0 for unlimited (limited
# only by storage space) or any integer for stopping after a while.
total = appuifw.query(u"Total photos (0 for unlimited):", "number")
# Create a new object and call its start function.
tlCam = timeLapseCamera()
tlCam.start(interval, total)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment