-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFire Detection.py
More file actions
66 lines (44 loc) · 1.47 KB
/
Copy pathFire Detection.py
File metadata and controls
66 lines (44 loc) · 1.47 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import numpy as np
import cv2
import os
import sys
import time
datasets = 'detected'
path = os.path.join(datasets)
(width, height) = (130, 100)
fire_cascade = cv2.CascadeClassifier('fire_detection.xml')
#fire_detection.xml file & this code should be in the same folder while running the code
cap = cv2.VideoCapture(0)
while 1:
ret, img = cap.read()
##Gaussian Blurring
kernel = np.ones((7,7),np.float32)/25
img1 = cv2.filter2D(img,-1,kernel)
cv2.imshow('Gaussian',img1)
## Bilateral Filter for Edge Enhancement
img3 = cv2.bilateralFilter(img1,9,75,75)
cv2.imshow('Bilateral',img3)
## cv2.imshow('imgorignal',img)
gray = cv2.cvtColor(img3,cv2.COLOR_BGR2GRAY)
cv2.imshow('Grayscale',gray)
fire = fire_cascade.detectMultiScale(gray, 1.2, 5)
a=str(fire)
for (x,y,w,h) in fire:
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = img[y:y+h, x:x+w]
if a>='302 322 61 61' :
count = 1
while count < 60:
img_resize = cv2.resize(roi_color, (width, height))
cv2.imwrite('%s/%s.jpg' % (path,count), img_resize)
count += 1
print ('Fire is detected..!')
cv2.imwrite("first.jpg",img)
time.sleep(0.2)
cv2.imshow('img',img)
k = cv2.waitKey(30) & 0xff
if k == 27:
break
cap.release()
cv2.destroyAllWindows()