forked from avinashkranjan/Amazing-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflameDect-v.py
executable file
·61 lines (52 loc) · 1.69 KB
/
flameDect-v.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
52
53
54
55
56
57
58
59
60
61
# *-* coding:utf-8 *-*
import numpy as np
import cv2
import time
t = time.time()
"""读视频文件"""
vName = '../video/Boat_Fire_Stream.wmv'
cap = cv2.VideoCapture(vName)
tm = time.time()
"""二值化图像并取白色区域为火灾区域,用红色方框标出"""
while 1:
ret, frame = cap.read()
for i in xrange(50):
if i % 50 != 0:
break
else:
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
ret, binary = cv2.threshold(gray, 220, 255, cv2.THRESH_BINARY)
# e1 = cv2.getTickCount()
t1 = time.time()
height, width = binary.shape
x1, y1 = width, height
x2, y2 = 0, 0
n = 1
for i in range(height):
for j in range(width):
if binary[i][j] == 255:
if i < x1:
x1 = i
if i > x2:
x2 = i
if j < y1:
y1 = j
if j > y2:
y2 = j
# e2 = cv2.getTickCount()
t2 = time.time()
# print e2 - e1
print t2 - t1
cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 0, 255), 3)
cv2.rectangle(gray, (x1, y1), (x2, y2), (0, 0, 255), 3)
cv2.rectangle(binary, (x1, y1), (x2, y2), (255), 2)
cv2.imshow('frame', frame)
cv2.imshow('gray', gray)
cv2.imshow('binary', binary)
t3 = time.time()
print 'total time %f' % (t3 - t)
print x1, y1, x2, y2
if cv2.waitKey(5) & 0xFF == 27:
break
cap.release()
cv2.destroyAllWindows()