File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ import cv2
2+ import numpy as np
3+
4+ #video_file = "video_1.mp4"
5+ video = cv2 .VideoCapture (0 )
6+
7+ while True :
8+ (grabbed , frame ) = video .read ()
9+ if not grabbed :
10+ break
11+
12+ blur = cv2 .GaussianBlur (frame , (21 , 21 ), 0 )
13+ hsv = cv2 .cvtColor (blur , cv2 .COLOR_BGR2HSV )
14+
15+ lower = [18 , 50 , 50 ]
16+ upper = [35 , 255 , 255 ]
17+ lower = np .array (lower , dtype = "uint8" )
18+ upper = np .array (upper , dtype = "uint8" )
19+ mask = cv2 .inRange (hsv , lower , upper )
20+
21+
22+
23+ output = cv2 .bitwise_and (frame , hsv , mask = mask )
24+ no_red = cv2 .countNonZero (mask )
25+ cv2 .imshow ("output" , output )
26+ #print("output:", frame)
27+ if int (no_red ) > 20000 :
28+ print ('Fire detected' )
29+ #print(int(no_red))
30+ #print("output:".format(mask))
31+ if cv2 .waitKey (1 ) & 0xFF == ord ('q' ):
32+ break
33+
34+ cv2 .destroyAllWindows ()
35+ video .release ()
You can’t perform that action at this time.
0 commit comments