forked from niladri30/Fire-detection-using-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfire_detection.py
35 lines (27 loc) · 827 Bytes
/
fire_detection.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
import cv2
import numpy as np
#video_file = "video_1.mp4"
video = cv2.VideoCapture(0)
while True:
(grabbed, frame) = video.read()
if not grabbed:
break
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)
cv2.imshow("output", output)
#print("output:", frame)
if int(no_red) > 20000:
print ('Fire detected')
#print(int(no_red))
#print("output:".format(mask))
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
video.release()