Last active
January 22, 2019 20:27
-
-
Save JarrettR/89c6eec8447b89511e1bf08af4691092 to your computer and use it in GitHub Desktop.
This file contains 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
from io import BytesIO | |
from time import sleep, time | |
import picamera | |
from PIL import Image | |
import imgcompare | |
from Adafruit_IO import Client, Feed | |
ADAFRUIT_IO_KEY = '' | |
ADAFRUIT_IO_USERNAME = 'jrainimo' | |
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY) | |
feeds = aio.feeds() | |
print(feeds) | |
try: | |
temperature_feed = aio.feeds('tesy') | |
except: | |
temperature_feed = Feed(name="tesy") | |
response = aio.create_feed(temperature_feed) | |
aio.send(temperature_feed.key, '5.87') | |
#Wait for SSHFS to initialise | |
print('Begin') | |
#sleep(5) | |
try: | |
extrema_high_feed = aio.feeds('extrema') | |
except: | |
pass | |
#extrema_high_feed = Feed(name="extrema_high") | |
#response = aio.create_feed(extrema_high_feed) | |
try: | |
sse_feed = aio.feeds('difference') | |
except: | |
pass | |
#sse_feed = Feed(name="sse") | |
#response = aio.create_feed(sse_feed) | |
with picamera.PiCamera(resolution=(2592, 1944)) as camera: | |
# Set ISO to the desired value | |
camera.iso = 1600 | |
# Wait for the automatic gain control to settle | |
sleep(2) | |
# Now fix the values | |
camera.shutter_speed = camera.exposure_speed | |
camera.exposure_mode = 'off' | |
g = camera.awb_gains | |
camera.awb_mode = 'off' | |
camera.awb_gains = g | |
oldImage = None | |
timestamp = time() | |
timeDelay = 15 | |
#for img in camera.capture_continuous(stream, format='jpeg', quality=100): | |
while True: | |
#while oldImage == None: | |
try: | |
stream = BytesIO() | |
camera.capture(stream, format='jpeg', quality=100) | |
print('Captured') | |
print(' ISO : ', camera.iso) | |
print(' shutter_speed: ', camera.shutter_speed) | |
print(' exposure_mode: ', camera.exposure_mode) | |
print(' awb_gains : ', camera.awb_gains) | |
print(' settings : ', camera.exif_tags) | |
stream.truncate() | |
stream.seek(0) | |
image = Image.open(stream) | |
extrema = image.convert("L").getextrema() | |
if extrema == (0, 0): | |
print('all black') | |
elif extrema == (1, 1): | |
print('all white') | |
else: | |
#MQTT Extrema (high value only) | |
print('Extrema:', extrema) | |
extrema_high = '%.2f'%(extrema[1]) | |
print('extrema_high:', extrema_high) | |
try: | |
aio.send(extrema_high_feed.key, str(extrema_high)) | |
except Exception as e: | |
print(e) | |
pass | |
if oldImage is not None: | |
sse = imgcompare.image_diff_percent(image,oldImage) | |
sse = '%.2f'%(sse) | |
try: | |
sleep(1) | |
aio.send(sse_feed.key, str(sse)) | |
except Exception as e: | |
print(e) | |
pass | |
print('sse:', sse) | |
oldImage = image | |
filename = 'date +"%Y-%m-%d_%H:%M:%S"' | |
path = '/root/images/hd/timelapse/' | |
filename = 'file' + str(int(timestamp)) + '.jpg' | |
print('Saving as ', filename) | |
image.save(path + filename) | |
del(stream) | |
except Exception as e: | |
print(e) | |
pass | |
print('Waiting') | |
while time() < (timestamp + timeDelay): | |
sleep(1) | |
print('Time: ', time()) | |
timestamp = timestamp + timeDelay |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment