Revision 00f193bf
Added by David Sorber over 10 years ago
| software/security_cam/client/security_cam.py | ||
|---|---|---|
|
#!/usr/bin/python3
|
||
|
import datetime
|
||
|
from multiprocessing import Process
|
||
|
import os
|
||
|
import subprocess
|
||
|
import sys
|
||
|
import time
|
||
|
|
||
|
# Globals
|
||
|
DELAY_DURATION = 15 # delay between taking pictures in seconds
|
||
|
IMAGE_PATH = '/mnt/images' # path where images will be stored
|
||
|
MAX_IMAGES = 4 # maximum number of images to keep
|
||
|
|
||
|
# Security webcam daemon
|
||
|
|
||
|
|
||
|
class ImageCapturer(Process):
|
||
|
|
||
|
def __init__(self):
|
||
|
Process.__init__(self)
|
||
|
|
||
|
def run(self):
|
||
|
self.running = True
|
||
|
|
||
|
while (self.running):
|
||
|
date_str = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
|
||
|
filename = os.path.join(IMAGE_PATH, 'image_{:s}.jpg'.format(date_str))
|
||
|
cmd = 'fswebcam -r 1080x720 --jpeg 85 -S 5 {:s}'.format(filename)
|
||
|
subprocess.call(cmd, shell=True)
|
||
|
time.sleep(DELAY_DURATION)
|
||
|
|
||
|
def main():
|
||
|
print('Image Capture\n')
|
||
|
|
||
|
ImageCapturer().start()
|
||
|
|
||
|
while True:
|
||
|
time.sleep(DELAY_DURATION - 5)
|
||
|
dir_contents = os.listdir(IMAGE_PATH)
|
||
|
if len(dir_contents) > MAX_IMAGES:
|
||
|
to_remove = sorted(dir_contents, reverse=True)[MAX_IMAGES:]
|
||
|
for filename in to_remove:
|
||
|
full_fname = os.path.join(IMAGE_PATH, filename)
|
||
|
os.remove(full_fname)
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
sys.exit(main())
|
||
Adding client-side security cam script.