import cv2 import datetime import time import numpy as np from pygame import mixer count = 0 def display(length): if length == 1: onestar = cv2.imread('src/images/*.png') outDoor[220:304, 54:214] = onestar elif length == 2: twostar = cv2.imread('src/images/**.png') outDoor[220:304, 54:214] = twostar elif length == 3: threestar = cv2.imread('src/images/***.png') outDoor[220:304, 54:214] = threestar elif length == 4: fourstar = cv2.imread('src/images/****.png') outDoor[220:304, 54:214] = fourstar def alert(): mixer.init() alert = mixer.Sound('src/noises/beep-07.wav') for i in range(5): alert.play() time.sleep(0.1) alert.play() def click_event(event, x, y, flags, param): if event == cv2.EVENT_LBUTTONDOWN: if 620 <= y <= 703 and 20 <= x <= 169: print('cam') global cam_status if cam_status == 0: cam_status = 1 elif cam_status == 1: cam_status = 0 elif 620 <= y <= 703 and 189 <= x <= 448: print('doorbell') alert() elif 620 <= y <= 703 and 468 <= x <= 734: print('open gate') global a a = datetime.datetime.now() global globalna globalna = 1 elif 620 <= y <= 703 and 754 <= x <= 945: print('listen') elif 620 <= y <= 703 and 965 <= x <= 1173: print('pick up') elif 620 <= y <= 703 and 1193 <= x <= 1267: print('off') cap.release() out.release() cv2.destroyAllWindows() def click_event2(event, x, y, flags, param): if event == cv2.EVENT_LBUTTONDOWN: global displayString if len(displayString) == 4: print('zero') displayString = "" if 348 <= y <= 370 and 59 <= x <= 86: print("1 outdoor") displayString = displayString + '1' print(displayString) if 348 <= y <= 370 and 100 <= x <= 128: print("2 outdoor") displayString = displayString + '2' print(displayString) if 348 <= y <= 370 and 142 <= x <= 169: print("3 outdoor") displayString = displayString + '3' print(displayString) if 390 <= y <= 412 and 59 <= x <= 86: print("4 outdoor") displayString = displayString + '4' print(displayString) if 390 <= y <= 412 and 100 <= x <= 128: print("5 outdoor") displayString = displayString + '5' print(displayString) if 390 <= y <= 412 and 142 <= x <= 169: print("6 outdoor") displayString = displayString + '6' print(displayString) if 431 <= y <= 453 and 59 <= x <= 86: print("7 outdoor") displayString = displayString + '7' print(displayString) if 431 <= y <= 453 and 100 <= x <= 128: print("8 outdoor") displayString = displayString + '8' print(displayString) if 431 <= y <= 453 and 142 <= x <= 169: print("9 outdoor") displayString = displayString + '9' print(displayString) if 472 <= y <= 495 and 59 <= x <= 86: print("* outdoor") displayString = displayString + '*' print(displayString) if 472 <= y <= 495 and 100 <= x <= 128: print("0 outdoor") displayString = displayString + '0' print(displayString) if 472 <= y <= 495 and 142 <= x <= 169: print("# outdoor") displayString = displayString + '#' print(displayString) display(len(displayString)) def notification(): not1 = cv2.imread('src/notification/not1.png') frame[50:50 + 139, 800:800 + 406] = not1 b = datetime.datetime.now() global a t = datetime.timedelta(0, 3) if (b - a) > t: global globalna globalna = 0 global a a = None global displayString displayString ="" i = 0 cam_status = 1 liczba = 0 globalna = 0 displayString3 = "jud" cap = cv2.VideoCapture(0) four_cc = cv2.VideoWriter_fourcc(*'XVID') out = cv2.VideoWriter('recordings/output.avi', four_cc, 10.0, (1280, 720)) cap.set(3, 1280) cap.set(4, 720) while cap.isOpened(): ret, frameprev = cap.read() if cam_status == 1: frame = frameprev elif cam_status == 0: frame = np.zeros((720, 1280, 3), np.uint8) if ret: font = cv2.FONT_HERSHEY_SIMPLEX actual_time = str(datetime.datetime.now().strftime("%b %d %Y %H:%M:%S")) frame = cv2.putText(frame, actual_time, (10, 50), font, 1, (0, 255, 255), 2, cv2.LINE_AA) menu = cv2.imread('src/images/menu.png')[620:720, 0:1280] frame[620:720, 0:1280] = menu icon1 = cv2.imread('src/icons/icon1.png') frame[640:640 + 63, 20:169] = icon1 icon2 = cv2.imread('src/icons/icon2.png') frame[640:640 + 63, 189:448] = icon2 icon3 = cv2.imread('src/icons/icon3.png') frame[640:640 + 63, 468:734] = icon3 icon4 = cv2.imread('src/icons/icon4.png') frame[640:640 + 63, 754:945] = icon4 icon5 = cv2.imread('src/icons/icon5.png') frame[640:640 + 63, 965:1173] = icon5 icon6 = cv2.imread('src/icons/icon6.png') frame[640:640 + 63, 1193:1267] = icon6 if globalna == 1: notification() cv2.imshow('frame', frame) outDoor = cv2.imread('src/images/outDoorPanel.png') display(len(displayString)) cv2.imshow('outDoor', outDoor) out.write(frameprev) cv2.setMouseCallback('frame', click_event) cv2.setMouseCallback('outDoor', click_event2) if cv2.waitKey(1) & 0xFF == ord('q'): break else: break cap.release() out.release() cv2.destroyAllWindows()