Skip to content

Instantly share code, notes, and snippets.

@jcurbo
Created November 12, 2017 02:19
Show Gist options
  • Save jcurbo/75fe167b17ce1e5e2a78bb930338a9da to your computer and use it in GitHub Desktop.
Save jcurbo/75fe167b17ce1e5e2a78bb930338a9da to your computer and use it in GitHub Desktop.
Quick and dirty picamera script for skycam
from picamera import PiCamera
from time import sleep
from fractions import Fraction
from datetime import datetime
from os import makedirs
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--iso", type=int, default=800, help="ISO to use")
parser.add_argument("--shutter", type=int, default=6000000, help="shutter speed in microseconds")
parser.add_argument("--single", action='store_true', help="Capture a single image only, instead of a timelapse")
parser.add_argument("--timelapse", type=int, default=60, help="Timelapse between captures")
args = parser.parse_args()
camera = PiCamera(
resolution=(1640,1232),
framerate=Fraction(1,6),
sensor_mode=4) # to enable binning
camera.shutter_speed = args.shutter
camera.iso = args.iso
sleep(2)
camera.exposure_mode = 'off'
skycam_homedir = "/home/james/allsky/skycam1/"
current_date = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
current_day = datetime.now().strftime('%Y-%m-%d')
makedirs("{}/{}".format(skycam_homedir, current_day), exist_ok=True)
if(args.single):
print("Operating in single capture mode")
camera.capture("{}/{}/skycam1_{}.jpg".format(skycam_homedir, current_day, current_date))
else:
print("Operating in timelapse mode, {} seconds between captures".format(args.timelapse))
for filename in camera.capture_continuous("{}/{}/skycam1_{}.jpg".format(skycam_homedir, current_day, current_date)):
print('Captured %s' % filename)
sleep(args.timelapse)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment