|
|
@ -7,6 +7,7 @@ import os
|
|
|
|
import glob
|
|
|
|
import glob
|
|
|
|
import time
|
|
|
|
import time
|
|
|
|
import pytz
|
|
|
|
import pytz
|
|
|
|
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import subprocess
|
|
|
|
from io import BytesIO
|
|
|
|
from io import BytesIO
|
|
|
|
from datetime import datetime
|
|
|
|
from datetime import datetime
|
|
|
@ -27,6 +28,7 @@ TIMEZONE = 'Australia/Sydney'
|
|
|
|
WAIT_TIME = 0.1
|
|
|
|
WAIT_TIME = 0.1
|
|
|
|
RECORDING_DURATION = 20
|
|
|
|
RECORDING_DURATION = 20
|
|
|
|
SILENT = True
|
|
|
|
SILENT = True
|
|
|
|
|
|
|
|
IMAGE_MASK = 'mask/overtopping-mask.png'
|
|
|
|
username = ''
|
|
|
|
username = ''
|
|
|
|
password = ''
|
|
|
|
password = ''
|
|
|
|
|
|
|
|
|
|
|
@ -229,6 +231,28 @@ def create_video():
|
|
|
|
subprocess.run(command)
|
|
|
|
subprocess.run(command)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_brightness(jpg_name, mask):
|
|
|
|
|
|
|
|
"""Get mean brighness of an image with a mask applied
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Load image
|
|
|
|
|
|
|
|
im = Image.open(jpg_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Load mask and resize of necessary
|
|
|
|
|
|
|
|
width, height = mask.size
|
|
|
|
|
|
|
|
im = im.resize((width, height), Image.LANCZOS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Apply mask to image
|
|
|
|
|
|
|
|
im.paste(mask, mask=mask)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Convert to greyscale
|
|
|
|
|
|
|
|
im_grey = im.convert('LA')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Calculate mean intensity
|
|
|
|
|
|
|
|
b = np.array(im_grey).mean()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return b
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create counter
|
|
|
|
# Create counter
|
|
|
|
t = []
|
|
|
|
t = []
|
|
|
|
|
|
|
|
|
|
|
@ -237,3 +261,17 @@ get_images()
|
|
|
|
|
|
|
|
|
|
|
|
# Create video
|
|
|
|
# Create video
|
|
|
|
create_video()
|
|
|
|
create_video()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Load image mask
|
|
|
|
|
|
|
|
mask = Image.open(os.path.join(pwd, IMAGE_MASK))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Find brightest image for current high tide
|
|
|
|
|
|
|
|
jpg_names = glob.glob(current_hightide_dir + '/jpg/*')
|
|
|
|
|
|
|
|
b = np.zeros(len(jpg_names))
|
|
|
|
|
|
|
|
for i, jpg_name in enumerate(jpg_names):
|
|
|
|
|
|
|
|
b[i] = get_brightness(jpg_name, mask)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Copy brightest image to root directory for current year
|
|
|
|
|
|
|
|
src_name = jpg_names[b.argmax()]
|
|
|
|
|
|
|
|
dst_name = current_hightide_dir + '.jpg'
|
|
|
|
|
|
|
|
shutil.copy(src_name, dst_name)
|
|
|
|