Beruflich Dokumente
Kultur Dokumente
import numpy as np
from datetime import datetime
import time
import os
import cv2
import imutils
# Mask image such that the algorithm is triggered only by someone at the front door
def mask_image(img):
mask = np.zeros((img.shape[0], img.shape[1]), dtype="uint8")
pts = np.array([[240, 475], [240, 420], [310, 420], [375, 410], [525, 350],
[550, 100], [635,100], [635, 475]], dtype=np.int32)
cv2.fillConvexPoly(mask, pts, 255)
pts = np.array([[1, 395], [1, 315], [110, 305],[110, 365]], dtype=np.int32)
cv2.fillConvexPoly(mask, pts, 255)
masked = cv2.bitwise_and(img, img, mask=mask)
gray = imutils.resize(masked, width=200)
gray = cv2.cvtColor(gray, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (21,21), 0)
return gray
# keep looping
counter = -1
while True:
counter = counter + 1
print (counter)
time.sleep(0.01)
detector_total = np.uint64(0)
detector = np.zeros((gray2.shape[0], gray2.shape[1], 3), dtype="uint8")
for i in range(0,gray2.shape[0]):
for j in range(0, gray2.shape[1]):
if int(gray1[i,j])-int(gray2[i,j]) > pixel_thres or
int(gray2[i,j])-int(gray1[i,j]) > pixel_thres and int(gray1[i,j]) > 0:
detector[i,j] = 255
detector_total = np.uint64(np.sum(detector))
print ("detector_total = ")
print (detector_total)
print (" ")
t_stop = time.time()
t_video = t_stop - t_start
time.sleep(0.1)
print ("Finished recording .h264...now converting to .mp4")
command2 = 'MP4Box -add ' + timestr + '.h264 ' + timestr + '.mp4'
os.system(command2)
# Now send email to the user to confirm video has been recorded
# To/from information
toAdd = 'john.98.ed@gmail.com'
fromAdd = smtpUser
subject = 'Ring recording from: ' + f_time
msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = fromAdd
msg['To'] = toAdd
msg.preamble = "Photo @ " + f_time
# Email text
body = email.mime.text.MIMEText("Ring Video: " + f_time + ", video
length: " + str(t_video))
msg.attach(body)