Last active
October 28, 2015 00:23
-
-
Save RealOrangeOne/9b6808d60174101a7832 to your computer and use it in GitHub Desktop.
Raspberry Pi time lapse program. Keeps images in order without timestamp
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
# Using library at http://pimylifeup.com/raspberry-pi-time-lapse/ | |
from glob import glob | |
import os.path | |
import subprocess, logging | |
FILE_PATH = "/home/pi/timelapse/" # Where to store the files | |
CAPTURE_COMMAND = "raspistill -o {0}" # To be formatted later with file name | |
FORMAT = "[%(levelname)s] %(message)s" | |
LOG_FILE = FILE_PATH + "log.txt" | |
logging.basicConfig(format=FORMAT, filename=LOG_FILE, level=logging.DEBUG) | |
logging.info("Starting capture of image...") | |
files = glob(FILE_PATH + "*") # Get a list of files in the directory | |
file_index = 0 | |
while True: | |
file_name = FILE_PATH + str(file_index) + ".jpg" | |
if os.path.isfile(file_name) and file_name in files: # Double check file exists, just in case | |
file_index += 1 | |
else: | |
break # If there is no file by that name, then we can save to it | |
final_path = FILE_PATH + str(file_index) + ".jpg" | |
logging.info("Found image slot at " + final_path) | |
command = CAPTURE_COMMAND.format(final_path) # Build the string command | |
retry_count = 5 | |
while retry_count != 0: | |
logging.info("Executing command '{0}'".format(command)) | |
output = subprocess.check_output(command, shell=True) # Run the command to capture the images | |
logging.debug("Got output " + output) | |
if os.path.isfile(final_path): # Check that the file does exist | |
logging.info("File Saved successfully to " + final_path) | |
break | |
else: | |
logging.error("Something went wrong saving the file, retrying...") | |
retry_count -= 1 | |
if retry_count == 0: | |
exit(1) # Tell the computer something went wrong | |
else: | |
exit(0) # Exit with no errors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment