Pracownia_programowania/src/smart_intercom.py

771 lines
26 KiB
Python
Raw Normal View History

2020-01-17 00:23:07 +01:00
import cv2
import datetime
import time
import numpy as np
2020-01-31 00:52:57 +01:00
import pygame
2020-01-17 00:23:07 +01:00
import pickle
import copy
2020-01-31 00:52:57 +01:00
import os
import mysql.connector
from shutil import copyfile
2020-01-17 00:23:07 +01:00
def alert():
2020-01-31 00:52:57 +01:00
pygame.mixer.init()
pygame.mixer.music.load("noises/doorbell_sound.mp3")
pygame.mixer.music.play()
2020-01-17 00:23:07 +01:00
def click_event(event, x, y, flags, param):
if event == cv2.EVENT_LBUTTONDOWN:
2020-01-31 00:52:57 +01:00
global cam_status, show_who, keyboardString, keyboardWork, keyboardChar, show_list, wait_add, refresh
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
if 640 <= y <= 703 and 20 <= x <= 188: # cam
2020-01-17 00:23:07 +01:00
if cam_status == 1:
cam_status = 0
elif cam_status == 0:
cam_status = 1
2020-01-31 00:52:57 +01:00
elif 265 <= y <= 328 and 255 <= x <= 423 and show_who == 1: # cam2
if cam_status == 1:
cam_status = 0
elif cam_status == 0:
cam_status = 1
show_who = 0
elif 640 <= y <= 703 and 218 <= x <= 422: # open gate
2020-01-17 00:23:07 +01:00
global wait_notification
wait_notification = 1
2020-02-01 15:25:16 +01:00
pygame.mixer.init()
pygame.mixer.music.load("noises/beep-07.wav")
pygame.mixer.music.play()
2020-01-31 00:52:57 +01:00
elif 640 <= y <= 703 and 452 <= x <= 694: # take a photo
global screenshot, keyboard, choose
screenshot = 1
choose = 1
elif 640 <= y <= 703 and 724 <= x <= 924: # statistics
global stats_status
if stats_status == 1:
stats_status = 0
elif stats_status == 0:
stats_status = 1
elif 640 <= y <= 703 and 954 <= x <= 1132: # refresh
os.system('python3 faces-train.py')
refresh = 1
elif 640 <= y <= 703 and 1162 <= x <= 1270: # off
2020-01-19 17:09:12 +01:00
with open("variable.pickle", "wb") as f:
pickle.dump(name_of_photo, f)
2020-01-17 00:23:07 +01:00
cap.release()
out.release()
cv2.destroyAllWindows()
exit()
2020-01-31 00:52:57 +01:00
os.system('python3 faces-train.py')
if(show_list == 1):
if 350 <= y <= 413 and 400 <= x <= 650:
show_list = 0
elif 175 <= y <= 210 and 716 <= x <= 950:
print("1")
show_list = 0
print(name_of_photo[0]-1)
copyfile("photos/" + str(name_of_photo[0]-1) + ".png",
"faces/" + files[0] + "/" + str(name_of_photo[0]-1) + ".png")
wait_add = 1
elif 211 <= y <= 250 and 716 <= x <= 950:
print("2")
show_list = 0
copyfile("photos/" + str(name_of_photo[0]-1) + ".png",
"faces/" + files[1] + "/" + str(name_of_photo[0]-1) + ".png")
wait_add = 1
elif 251 <= y <= 290 and 716 <= x <= 950:
print("3")
show_list = 0
copyfile("photos/" + str(name_of_photo[0]-1) + ".png",
"faces/" + files[2] + "/" + str(name_of_photo[0]-1) + ".png")
wait_add = 1
elif 291 <= y <= 330 and 716 <= x <= 950:
print("4")
show_list = 0
copyfile("photos/" + str(name_of_photo[0]-1) + ".png",
"faces/" + files[3] + "/" + str(name_of_photo[0]-1) + ".png")
wait_add = 1
elif 331 <= y <= 370 and 716 <= x <= 950:
print("5")
show_list = 0
copyfile("photos/" + str(name_of_photo[0]-1) + ".png",
"faces/" + files[4] + "/" + str(name_of_photo[0]-1) + ".png")
wait_add = 1
elif 371 <= y <= 410 and 716 <= x <= 950:
print("6")
show_list = 0
copyfile("photos/" + str(name_of_photo[0]-1) + ".png",
"faces/" + files[4] + "/" + str(name_of_photo[0]-1) + ".png")
wait_add = 1
if(keyboard == 1):
if 191 <= y <= 266 and 730 <= x <= 808: # ADD
print("1")
keyboardString = keyboardString + keyboardChar
keyboardWork = ""
keyboardChar = ""
elif 191 <= y <= 266 and 809 <= x <= 886: # 2
# print("2")
keyboardWork = keyboardWork + '2'
print(keyboardWork)
keyboardChar = keyboardLogic(2, len(keyboardWork))
elif 191 <= y <= 266 and 887 <= x <= 962: # 3
print("3")
keyboardWork = keyboardWork + '3'
print(keyboardWork)
keyboardChar = keyboardLogic(3, len(keyboardWork))
elif 267 <= y <= 344 and 730 <= x <= 808: # 4
print("4")
keyboardWork = keyboardWork + '4'
print(keyboardWork)
keyboardChar = keyboardLogic(4, len(keyboardWork))
elif 267 <= y <= 344 and 809 <= x <= 886: # 5
print("5")
keyboardWork = keyboardWork + '5'
print(keyboardWork)
keyboardChar = keyboardLogic(5, len(keyboardWork))
elif 267 <= y <= 344 and 887 <= x <= 962: # 6
print("6")
keyboardWork = keyboardWork + '6'
print(keyboardWork)
keyboardChar = keyboardLogic(6, len(keyboardWork))
elif 345 <= y <= 420 and 730 <= x <= 808: # 7
print("7")
keyboardWork = keyboardWork + '7'
print(keyboardWork)
keyboardChar = keyboardLogic(7, len(keyboardWork))
elif 345 <= y <= 420 and 809 <= x <= 886: # 8
print("8")
keyboardWork = keyboardWork + '8'
print(keyboardWork)
keyboardChar = keyboardLogic(8, len(keyboardWork))
elif 345 <= y <= 420 and 887 <= x <= 962: # 9
print("9")
keyboardWork = keyboardWork + '9'
print(keyboardWork)
keyboardChar = keyboardLogic(9, len(keyboardWork))
elif 191 <= y <= 266 and 650 <= x <= 715: # DONE
os.mkdir("faces/" + keyboardString)
copyfile("photos/" + str(name_of_photo[0]-1) + ".png",
"faces/" + keyboardString + "/" + str(name_of_photo[0]-1) + ".png")
keyboard = 0
wait_add = 1
elif 267 <= y <= 344 and 650 <= x <= 715: # close
keyboard = 0
print("close")
if(choose == 1):
if 200 <= y <= 263 and 716 <= x <= 808: # new
choose = 0
keyboard = 1
elif 200 <= y <= 263 and 817 <= x <= 967: # existing
choose = 0
show_list = 1
elif 273 <= y <= 336 and 716 <= x <= 966:
print("close")
choose = 0
def keyboardLogic(key, length):
if key == 2:
if length % 3 == 1:
return "a"
if length % 3 == 2:
return "b"
if length % 3 == 0:
return "c"
if key == 3:
if length % 3 == 1:
return "d"
if length % 3 == 2:
return "e"
if length % 3 == 0:
return "f"
if key == 4:
if length % 3 == 1:
return "g"
if length % 3 == 2:
return "h"
if length % 3 == 0:
return "i"
if key == 5:
if length % 3 == 1:
return "j"
if length % 3 == 2:
return "k"
if length % 3 == 0:
return "l"
if key == 6:
if length % 3 == 1:
return "m"
if length % 3 == 2:
return "n"
if length % 3 == 0:
return "o"
if key == 8:
if length % 3 == 1:
return "t"
if length % 3 == 2:
return "u"
if length % 3 == 0:
return "v"
if key == 7:
if length % 4 == 1:
return "p"
if length % 4 == 2:
return "q"
if length % 4 == 3:
return "r"
if length % 4 == 0:
return "s"
if key == 9:
if length % 4 == 1:
return "w"
if length % 4 == 2:
return "x"
if length % 4 == 3:
return "y"
if length % 4 == 0:
return "z"
2020-01-17 00:23:07 +01:00
def click_event2(event, x, y, flags, param):
if event == cv2.EVENT_LBUTTONDOWN:
global displayString
2020-01-31 00:52:57 +01:00
if 348 <= y <= 370 and 59 <= x <= 86: # 1 outdoor
2020-01-17 00:23:07 +01:00
displayString = displayString + '1'
2020-01-31 00:52:57 +01:00
if 348 <= y <= 370 and 100 <= x <= 128: # 2 outdoor
2020-01-17 00:23:07 +01:00
displayString = displayString + '2'
2020-01-31 00:52:57 +01:00
if 348 <= y <= 370 and 142 <= x <= 169: # 3 outdoor
2020-01-17 00:23:07 +01:00
displayString = displayString + '3'
2020-01-31 00:52:57 +01:00
if 390 <= y <= 412 and 59 <= x <= 86: # 4 outdoor
2020-01-17 00:23:07 +01:00
displayString = displayString + '4'
2020-01-31 00:52:57 +01:00
if 390 <= y <= 412 and 100 <= x <= 128: # 5 outdoor
2020-01-17 00:23:07 +01:00
displayString = displayString + '5'
2020-01-31 00:52:57 +01:00
if 390 <= y <= 412 and 142 <= x <= 169: # 6 outdoor
2020-01-17 00:23:07 +01:00
displayString = displayString + '6'
2020-01-31 00:52:57 +01:00
if 431 <= y <= 453 and 59 <= x <= 86: # 7 outdoor
2020-01-17 00:23:07 +01:00
displayString = displayString + '7'
2020-01-31 00:52:57 +01:00
if 431 <= y <= 453 and 100 <= x <= 128: # 8 outdoor
2020-01-17 00:23:07 +01:00
displayString = displayString + '8'
2020-01-31 00:52:57 +01:00
if 431 <= y <= 453 and 142 <= x <= 169: # 9 outdoor
2020-01-17 00:23:07 +01:00
displayString = displayString + '9'
2020-01-31 00:52:57 +01:00
if 472 <= y <= 495 and 59 <= x <= 86: # * outdoor
2020-01-17 00:23:07 +01:00
displayString = displayString + '*'
2020-01-31 00:52:57 +01:00
if 472 <= y <= 495 and 100 <= x <= 128: # 0 outdoor
2020-01-17 00:23:07 +01:00
displayString = displayString + '0'
2020-01-31 00:52:57 +01:00
if 472 <= y <= 495 and 142 <= x <= 169: # outdoor
2020-01-17 00:23:07 +01:00
displayString = displayString + '#'
2020-01-31 00:52:57 +01:00
if 465 <= y <= 495 and 192 <= x <= 227: # bell outdoor
alert()
2020-01-17 00:23:07 +01:00
display_work(len(displayString))
def display_work(length):
2020-02-01 15:25:16 +01:00
global displayString, switch
2020-01-17 00:23:07 +01:00
if length == 1:
2020-01-31 00:52:57 +01:00
putOnDisplay(outDoor, 220, 304, 54, 214, 'images/*.png')
2020-02-01 15:25:16 +01:00
switch = 1
2020-01-17 00:23:07 +01:00
elif length == 2:
2020-01-31 00:52:57 +01:00
putOnDisplay(outDoor, 220, 304, 54, 214, 'images/**.png')
2020-01-17 00:23:07 +01:00
elif length == 3:
2020-01-31 00:52:57 +01:00
putOnDisplay(outDoor, 220, 304, 54, 214, 'images/***.png')
2020-01-17 00:23:07 +01:00
elif length == 4:
if displayString == "1234":
2020-01-31 00:52:57 +01:00
putOnDisplay(outDoor, 220, 304, 54, 214, 'images/goodpass.png')
global wait_notification
wait_notification = 1
2020-02-01 15:25:16 +01:00
if (switch == 1):
pygame.mixer.init()
pygame.mixer.music.load("noises/beep-07.wav")
pygame.mixer.music.play()
switch = 0
2020-01-19 17:09:12 +01:00
if wait_seconds2(3) == True:
2020-01-31 00:52:57 +01:00
name_of_photo[2] = name_of_photo[2] + 1
2020-01-17 00:23:07 +01:00
displayString = displayString + '#'
2020-02-01 15:25:16 +01:00
2020-01-17 00:23:07 +01:00
else:
2020-01-31 00:52:57 +01:00
putOnDisplay(outDoor, 220, 304, 54, 214, 'images/badpass.png')
if wait_seconds2(3) == True:
name_of_photo[3] = name_of_photo[3] + 1
displayString = displayString + '#'
2020-01-17 00:23:07 +01:00
elif length == 5:
displayString = ''
def notification():
2020-01-31 00:52:57 +01:00
putOnDisplay(frame, 50, 113, 800, 1116, 'images/not1.png')
2020-01-19 17:09:12 +01:00
if wait_seconds3(3) == True:
2020-01-17 00:23:07 +01:00
global wait_notification
wait_notification = 0
def putOnDisplay(frame, fheight, sheight, fwidth,
swidth, src):
img = cv2.imread(src)
frame[fheight: sheight, fwidth: swidth] = img
def putTimeOnDisplay(frame):
font = cv2.FONT_HERSHEY_SIMPLEX
actual_time = str(
datetime.datetime.now().strftime("%b %d %Y %H:%M:%S"))
cv2.putText(frame, actual_time, (10, 50),
2020-01-31 00:52:57 +01:00
font, 1, (255, 255, 255), 2, cv2.LINE_AA)
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
def wait_seconds(time, temp):
if temp == None:
temp = datetime.datetime.now()
2020-01-17 00:23:07 +01:00
else:
2020-01-31 00:52:57 +01:00
live_time = datetime.datetime.now()
time_to_expire = datetime.timedelta(0, time)
if (live_time - temp) < time_to_expire:
live_time = datetime.datetime.now()
else:
temp = None
return True
2020-01-17 00:23:07 +01:00
2020-01-19 17:09:12 +01:00
def wait_seconds1(time):
global temp1
if temp1 == None:
temp1 = datetime.datetime.now()
2020-01-17 00:23:07 +01:00
else:
live_time = datetime.datetime.now()
time_to_expire = datetime.timedelta(0, time)
2020-01-19 17:09:12 +01:00
if (live_time - temp1) < time_to_expire:
2020-01-17 00:23:07 +01:00
live_time = datetime.datetime.now()
else:
2020-01-19 17:09:12 +01:00
temp1 = None
return True
def wait_seconds2(time):
global temp2
if temp2 == None:
temp2 = datetime.datetime.now()
else:
live_time = datetime.datetime.now()
time_to_expire = datetime.timedelta(0, time)
if (live_time - temp2) < time_to_expire:
live_time = datetime.datetime.now()
else:
temp2 = None
return True
def wait_seconds3(time):
global temp3
if temp3 == None:
temp3 = datetime.datetime.now()
else:
live_time = datetime.datetime.now()
time_to_expire = datetime.timedelta(0, time)
if (live_time - temp3) < time_to_expire:
live_time = datetime.datetime.now()
else:
temp3 = None
2020-01-17 00:23:07 +01:00
return True
2020-01-31 00:52:57 +01:00
def wait_seconds4(time):
global temp4
if temp4 == None:
temp4 = datetime.datetime.now()
else:
live_time = datetime.datetime.now()
time_to_expire = datetime.timedelta(0, time)
if (live_time - temp4) < time_to_expire:
live_time = datetime.datetime.now()
else:
temp4 = None
return True
def wait_seconds5(time):
global temp5
if temp5 == None:
temp5 = datetime.datetime.now()
else:
live_time = datetime.datetime.now()
time_to_expire = datetime.timedelta(0, time)
if (live_time - temp5) < time_to_expire:
live_time = datetime.datetime.now()
else:
temp5 = None
return True
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
def wait_seconds6(time):
global temp6
if temp6 == None:
temp6 = datetime.datetime.now()
else:
live_time = datetime.datetime.now()
time_to_expire = datetime.timedelta(0, time)
if (live_time - temp6) < time_to_expire:
live_time = datetime.datetime.now()
else:
temp6 = None
return True
def most_frequent(List):
2020-01-17 00:23:07 +01:00
return max(set(List), key=List.count)
2020-01-31 00:52:57 +01:00
def putStatsOnDisplay():
font = cv2.FONT_HERSHEY_SIMPLEX
putOnDisplay(frame, 68, 358, 400, 1188, "images/background_stats.png")
cv2.putText(frame, "Good passwrods:"+str(name_of_photo[2]), (430, 100),
font, 1, (255, 255, 255), 2, cv2.LINE_AA)
cv2.putText(frame, "Bad passwords:"+str(name_of_photo[3]), (430, 140),
font, 1, (255, 255, 255), 2, cv2.LINE_AA)
mycursor.execute(
"SELECT * FROM Smart_intercom.visitorsv2 WHERE date = (SELECT MAX(date) FROM Smart_intercom.visitorsv2);")
myresult = mycursor.fetchone()
name = myresult[0]
date = str(myresult[1])
cv2.putText(frame, "Last visit: " + name + " at: " + date, (430, 180),
font, 1, (255, 255, 255), 2, cv2.LINE_AA)
mycursor.execute(
"SELECT name, COUNT(name) FROM Smart_intercom.visitorsv2 GROUP BY name ORDER BY COUNT(name) DESC LIMIT 3;")
myresult = mycursor.fetchall()
top1 = [myresult[0][0], str(myresult[0][1])]
top2 = [myresult[1][0], str(myresult[1][1])]
top3 = [myresult[2][0], str(myresult[2][1])]
cv2.putText(frame, "Top visitors:", (430, 220),
font, 1, (255, 255, 255), 2, cv2.LINE_AA)
cv2.putText(frame, "1. " + top1[0] + " ( " + top1[1] + " )", (460, 260),
font, 1, (255, 255, 255), 2, cv2.LINE_AA)
cv2.putText(frame, "2. " + top2[0] + " ( " + top2[1] + " )", (460, 300),
font, 1, (255, 255, 255), 2, cv2.LINE_AA)
cv2.putText(frame, "3. " + top3[0] + " ( " + top3[1] + " )", (460, 340),
font, 1, (255, 255, 255), 2, cv2.LINE_AA)
2020-01-17 00:23:07 +01:00
# Declaration
2020-02-01 15:25:16 +01:00
global displayString, wait_notification, wait_add, temp1, temp2, temp3, temp4, switch, temp5, temp6, refresh, name_of_photo, stats_status, screenshot, cam_status, show_who, is_recording, show_list, choose, keyboard, keyboardChar, keyboardString, keyboardWork
2020-01-31 00:52:57 +01:00
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="rootpasswordgiven",
database="Smart_intercom"
)
mycursor = mydb.cursor()
path = str(os.path.dirname(os.path.realpath(__file__)))+"/recordings"
2020-01-17 00:23:07 +01:00
displayString = ""
2020-01-31 00:52:57 +01:00
keyboardString = ""
keyboardWork = ""
keyboardChar = ""
2020-01-19 17:09:12 +01:00
temp1 = None
temp2 = None
temp3 = None
2020-01-31 00:52:57 +01:00
temp4 = None
temp5 = None
temp6 = None
wait_notification = 0
2020-02-01 15:25:16 +01:00
switch = 0
2020-01-31 00:52:57 +01:00
wait_add = 0
2020-01-19 17:09:12 +01:00
cam_status = 0
2020-01-31 00:52:57 +01:00
stats_status = 0
2020-01-17 00:23:07 +01:00
count = 0
2020-01-31 00:52:57 +01:00
show_who = 0
is_recording = 0
screenshot = 0
keyboard = 0
choose = 0
show_list = 0
List = []
out = None
refresh = 1
2020-02-01 15:25:16 +01:00
attempt = 15
2020-01-31 00:52:57 +01:00
font = cv2.FONT_HERSHEY_SIMPLEX
# Wyczytywanie zmiennych z pliku
# reset data
# name_of_photo = [1,1,0,0,"", []]
# [0] = photo number [1], = film number [2], = good password, [3] = bad password, [4] = last visit, [5] = history of visitors
2020-01-17 00:23:07 +01:00
2020-01-19 17:09:12 +01:00
with open("variable.pickle", "rb") as f:
name_of_photo = pickle.load(f)
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
# Ustawianie parametrów kamery
2020-02-01 15:25:16 +01:00
#cap = cv2.VideoCapture(0)
cap = cv2.VideoCapture('recordings/footage.mp4') # pokaz
# cap = cv2.VideoCapture('recordings/footage2.mp4') #zle
# cap = cv2.VideoCapture('recordings/footage3.mp4') #pokaz2
# cap = cv2.VideoCapture('recordings/footage4.mp4') #pokaz2
# cap = cv2.VideoCapture('recordings/footage5.mp4') #zle
#cap = cv2.VideoCapture('recordings/footage6.mp4') # pol na pol
2020-01-17 00:23:07 +01:00
cap.set(3, 1280)
cap.set(4, 720)
2020-01-31 00:52:57 +01:00
ret, frame1 = cap.read()
ret, frame2 = cap.read()
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
while True:
2020-02-01 15:25:16 +01:00
# print("brak")
2020-01-31 00:52:57 +01:00
if(refresh == 1):
# Wczytywanie listy osób które znajdują się w bazie
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
labels = {}
with open("labels.pickle", "rb") as f:
og_labels = pickle.load(f)
labels = {v: k for k, v in og_labels.items()}
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
# Wczytanie danych związanych z rozpoznawaniem twarzy
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
face_cascade = cv2.CascadeClassifier(
'cascades/data/haarcascade_frontalface_alt2.xml')
recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.read("trainner.yml")
print("odswierzam")
refresh = 0
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
# Utworzenie frame
ret, frame = cap.read()
# Wykrywanie ruchu
diff = cv2.absdiff(frame1, frame2)
gray = cv2.cvtColor(diff, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (5, 5), 0)
_, thresh = cv2.threshold(blur, 20, 255, cv2.THRESH_BINARY)
dilated = cv2.dilate(thresh, None, iterations=3)
contours, _ = cv2.findContours(
dilated, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
for contour in contours:
2020-02-01 15:25:16 +01:00
if cv2.contourArea(contour) < 20000:
2020-01-31 00:52:57 +01:00
continue
# aktualizacja czasu nagrywania (nagrywa do 20 sec po ostatnim wykryciu ruchu)
2020-02-01 15:25:16 +01:00
print("ruch")
2020-01-31 00:52:57 +01:00
temp4 = datetime.datetime.now()
if is_recording == 0:
# Rozpoczynanie nagrywania po wykryciu ruchu
is_recording = 1
cur_time = datetime.datetime.now().strftime("%b %d %Y %H:%M:%S")
four_cc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter(
'recordings/'+str(cur_time)+"-"+str(name_of_photo[1])+'.avi', four_cc, 10.0, (1280, 720))
name_of_photo[1] = name_of_photo[1] + 1
# Usuwanie dawnych nagrań z monitoringu
for root, dirs, files in os.walk(path):
for file in files:
if file.endswith(str(name_of_photo[1]-12)+'.avi'):
to_remove = str(file)
os.remove("recordings/" + to_remove)
frame1 = frame2
ret, frame2 = cap.read()
# Robienie zdjęć
if screenshot == 1:
if name_of_photo[0] >= 1000:
name_of_photo[0] = 1
img_item = "photos/" + str(name_of_photo[0]) + ".png"
print("Robie zdjecie nr: " + str(name_of_photo[0]))
cv2.imwrite(img_item, frame)
name_of_photo[0] = name_of_photo[0] + 1
screenshot = 0
# Zapisywanie nagrania i umieszczenie na nim czasu
if is_recording == 1:
putTimeOnDisplay(frame)
out.write(frame)
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
# Rozpoznawania twarzy
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
2020-01-17 00:23:07 +01:00
faces = face_cascade.detectMultiScale(
gray, scaleFactor=1.5, minNeighbors=5)
2020-02-01 15:25:16 +01:00
if len(List) < attempt:
2020-01-17 00:23:07 +01:00
for (x, y, w, h) in faces:
2020-01-31 00:52:57 +01:00
roi_gray = gray[y:y+h, x:x+w]
roi_color = frame[y:y + h, x:x + w]
2020-01-17 00:23:07 +01:00
id_, conf = recognizer.predict(roi_gray)
2020-01-31 00:52:57 +01:00
if conf >= 1:
2020-02-01 15:25:16 +01:00
print("rozpoznano:" + labels[id_])
2020-01-17 00:23:07 +01:00
count = count + 1
2020-01-31 00:52:57 +01:00
List.append(labels[id_])
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
# Wyłączenie widoku kamery w podglądzie
2020-02-01 15:25:16 +01:00
putOnDisplay(frame, 620, 720, 0, 1280, 'images/menu.png')
2020-01-31 00:52:57 +01:00
if cam_status == 0:
putOnDisplay(frame, 0, 720, 0, 1280, "images/black.png")
2020-02-01 15:25:16 +01:00
actual_time = str(
datetime.datetime.now().strftime("%H:%M:%S"))
cv2.putText(frame, actual_time, (700, 100),
font, 2, (255, 255, 255), 1, cv2.LINE_AA)
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
# Powiadomienie o rozpoznaniu osoby
2020-02-01 15:25:16 +01:00
if len(List) > 0 and len(List) < attempt:
2020-01-31 00:52:57 +01:00
print("lista: " + str(len(List)))
if wait_seconds6(30) == True:
List = []
2020-01-17 00:23:07 +01:00
2020-02-01 15:25:16 +01:00
if len(List) >= attempt:
2020-01-17 00:23:07 +01:00
font = cv2.FONT_HERSHEY_SIMPLEX
putOnDisplay(frame, 120, 255, 60, 430, "images/is_coming.png")
cv2.putText(frame, most_frequent(List), (80, 170),
2020-01-31 00:52:57 +01:00
font, 1, (255, 255, 255), 2, cv2.LINE_AA)
2020-01-17 00:23:07 +01:00
cv2.putText(frame, "is coming!", (250, 225),
2020-01-31 00:52:57 +01:00
font, 1, (255, 255, 255), 2, cv2.LINE_AA)
putOnDisplay(frame, 265, 328, 255, 423, 'images/camera.png')
show_who = 1
2020-01-19 17:09:12 +01:00
if wait_seconds1(10) == True:
2020-01-31 00:52:57 +01:00
statistic_time = datetime.datetime.now().strftime("%b %d %Y %H:%M:%S")
person = "'"+str(most_frequent(List))+"'"
sql = 'INSERT INTO Smart_intercom.visitorsv2 (name) VALUE (' + \
person+');'
mycursor.execute(sql)
mydb.commit()
2020-01-19 17:09:12 +01:00
List = []
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
outDoor = cv2.imread('images/outDoorPanel.png')
# Powiadomienie o wykryciu ruchu
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
if is_recording == 1:
putOnDisplay(outDoor, 151, 198, 161, 224, "images/led_on.png")
time_to_flashes = int(datetime.datetime.now().strftime("%S"))
if time_to_flashes % 2 == 1:
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
cv2.putText(frame, "motion detected", (500, 500),
font, 1, (255, 255, 255), 2, cv2.LINE_AA)
2020-01-17 00:23:07 +01:00
2020-02-01 15:25:16 +01:00
if wait_seconds4(5) == True:
2020-01-31 00:52:57 +01:00
is_recording = 0
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
# Wybór podczas robienia zdjecia #####################################
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
if(choose == 1):
putOnDisplay(frame, 200, 263, 716, 808, 'images/new.png')
putOnDisplay(frame, 200, 263, 817, 967, 'images/existing.png')
putOnDisplay(frame, 273, 336, 716, 966, 'images/cancel.png')
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
# Lista osob w bazie
if(wait_add == 1):
putOnDisplay(frame, 200, 263, 700, 878, 'images/success.png')
if wait_seconds5(3) == True:
wait_add = 0
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
if(show_list == 1):
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
putOnDisplay(frame, 130, 513, 350, 1002,
'images/background_list_persons.png')
putOnDisplay(frame, 350, 413, 400, 650, 'images/cancel.png')
cv2.putText(frame, "Who is this?", (400, 220),
font, 1, (255, 255, 255), 2, cv2.LINE_AA)
poz = 0
files = os.listdir(
str(os.path.dirname(os.path.realpath(__file__)))+"/faces")
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
for name in files:
cv2.putText(frame, name, (716, 200 + poz*40),
font, 1, (255, 255, 255), 2, cv2.LINE_AA)
poz = poz + 1
# Klawiatura
2020-01-17 00:23:07 +01:00
2020-01-31 00:52:57 +01:00
if keyboard == 1:
putOnDisplay(frame, 110, 430, 650, 970, 'images/keyboard.png')
cv2.putText(frame, keyboardString, (720, 170),
font, 1, (255, 255, 255), 2, cv2.LINE_AA)
cv2.putText(frame, keyboardChar, (720, 140),
font, 1, (255, 255, 255), 2, cv2.LINE_AA)
'''
pathe = str(os.path.dirname(os.path.realpath(__file__)))+"/faces"
files = os.listdir(pathe)
for name in files:
print(name)
dir = os.path.join(pathe,"python")
if not os.path.exists(dir):
os.mkdir(dir)
'''
# Umieszczenie więkości interfejsu
2020-02-01 15:25:16 +01:00
2020-01-31 00:52:57 +01:00
putOnDisplay(frame, 640, 640 + 63, 20, 188, 'images/camera.png')
putOnDisplay(frame, 640, 640 + 63, 218, 422, 'images/open_gate.png')
putOnDisplay(frame, 640, 640 + 63, 452, 694, 'images/take_a_photo.png')
putOnDisplay(frame, 640, 640 + 63, 724, 924, 'images/statistics.png')
putOnDisplay(frame, 640, 640 + 63, 954, 1132, 'images/refresh.png')
putOnDisplay(frame, 640, 640 + 63, 1162, 1270, 'images/off.png')
if wait_notification == 1:
notification()
if stats_status == 1:
putStatsOnDisplay()
# Funkcja odpowiedzialna za działanie klawiatury domofonu
display_work(len(displayString))
# Otwarcie okien
cv2.imshow('outDoor', outDoor)
cv2.imshow('frame', frame)
# Obsługa inputu interfejsu
cv2.setMouseCallback('frame', click_event)
cv2.setMouseCallback('outDoor', click_event2)
if cv2.waitKey(1) & 0xFF == ord('q'):
2020-01-17 00:23:07 +01:00
break
2020-01-31 00:52:57 +01:00
# Zapisywanie zmiennych do pliku
2020-01-19 17:09:12 +01:00
with open("variable.pickle", "wb") as f:
pickle.dump(name_of_photo, f)
2020-01-31 00:52:57 +01:00
if(out != None):
out.release()
2020-01-17 00:23:07 +01:00
cap.release()
cv2.destroyAllWindows()