-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
51 lines (36 loc) · 1.08 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import cv2
import numpy as np
import smtplib
import playsound
import threading
Alarm_Status = False
Fire_Reported = 0
def play_function():
while True:
playsound.playsound('Alarmsound.mp3',True)
video = cv2.VideoCapture(0)
while True:
(grabbed, frame) = video.read()
if not grabbed:
break
frame = cv2.resize(frame, (960, 540))
blur = cv2.GaussianBlur(frame, (21, 21), 0)
hsv = cv2.cvtColor(blur, cv2.COLOR_BGR2HSV)
lower = [18, 50, 50]
upper = [35, 255, 255]
lower = np.array(lower, dtype="uint8")
upper = np.array(upper, dtype="uint8")
mask = cv2.inRange(hsv, lower, upper)
output = cv2.bitwise_and(frame, hsv, mask=mask)
no_red = cv2.countNonZero(mask)
if int(no_red) > 25000:
Fire_Reported = Fire_Reported + 1
cv2.imshow("output", output)
if Fire_Reported >= 1:
if Alarm_Status == False:
threading.Thread(target=play_function).start()
Alarm_Status = True
if cv2.waitKey(1) == 13:
break
cv2.destroyAllWindows()
video.release()