-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfive.py
222 lines (127 loc) · 5.82 KB
/
five.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 13 13:52:07 2020
@author: sergey
"""
import numpy as np
import cv2, time, os
from tensorflow.keras import models
#from tensorflow.keras.preprocessing import image
import pytesseract as rec
# Загрузи НС
net = models.load_model('//home/sergey/AFE/SVG/Trucks_CB.h5')
ans = ['Фон','Грузовик']
#video = cv2.VideoCapture(0)
#video = cv2.VideoCapture('rtsp://admin:[email protected]:554/1/1')
video = cv2.VideoCapture('//home/sergey/AFE/SVG/video/2268-video.mp4') #759
video_d = cv2.VideoCapture('//home/sergey/AFE/SVG/video/2269-video.mp4')
video.set(cv2.CAP_PROP_POS_MSEC, 4*60*1000+46*1000)
ww = video.get(cv2.CAP_PROP_FRAME_WIDTH)
hh = video.get(cv2.CAP_PROP_FRAME_HEIGHT)
i=1
na=167
save_path = 'detected/'
def get_time (img):
#gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#ret, threshold_image = cv2.threshold(gray_image, 225, 255, cv2.THRESH_BINARY_INV)
ans = rec.image_to_string(img)
#cv2.imwrite('temp2.jpg', threshold_image)
return ans[:11]
def get_M_secs(s):
try:
hh = int(s[0:2])
mm = int(s[3:5])
ss = int(s[6:8])
ms = int(s[9:11])
#print (hh,mm,ss,ms)
return (hh*3600+mm*60+ss)*1000 + ms
except:
return -1
ret, frame = video_d.read()
rgb_image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
date_img = rgb_image[0:43,215:445,:]
ST = get_M_secs( get_time(date_img) )
print (ST)
print (get_time(date_img))
lastFrame = frame
video_d.release()
while(True):
ret, frame = video.read()
if ret:
if (i%1 == 0):
rgb_image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
date_img = rgb_image[0:43,215:445,:]
rgb_image = cv2.resize(rgb_image,(250,136))
rgb_image = rgb_image/255
rgb_image = np.expand_dims(rgb_image, axis = 0)
pred = net.predict(rgb_image)
try:
frame = cv2.resize(frame,(853, 480))
cv2.imshow('frame1',frame)
except:
pass
if pred[0][0] > 0.5:
print ('Грузовик')
current_T = get_time(date_img)
current = get_M_secs( current_T )
print ('текущие секунды ', current)
# захватил текущие милисекунды
# считаю разницу от начала
we_start_at = current - ST
#if we_start_at > 10000:
# we_start_at = we_start_at - 500
video_d = cv2.VideoCapture('video/2269-video.mp4')
video_d.set(cv2.CAP_PROP_POS_MSEC, we_start_at)
last_diff = we_start_at
print ('стартовый сдвиг', last_diff)
print ('время на первом видео ', current_T)
ret, frame_D = video_d.read()
rgb_image_D = cv2.cvtColor(frame_D, cv2.COLOR_BGR2RGB)
date_img_D = rgb_image_D[0:43,215:445,:]
#date_img_D = cv2.resize(date_img_D, (480, 80))
time_D = get_time(date_img_D)
current_D = get_M_secs( time_D )
if current < current_D:
we_start_at = we_start_at - (current_D - current) - 150
current_D = current_D - (current_D - current) - 150
video_d.set(cv2.CAP_PROP_POS_MSEC, we_start_at)
current_diff = current - current_D
print ('на втором видео стартую с времени ', time_D)
while (current_diff >= 0):
print (last_diff, current_diff)
lastFrame = frame_D
#last_diff = current_diff
last_time = time_D
ret, frame_D = video_d.read()
rgb_image_D = cv2.cvtColor(frame_D, cv2.COLOR_BGR2RGB)
date_img_D = rgb_image_D[0:43,215:445,:]
#date_img_D = cv2.resize(date_img_D, (480, 80))
time_D = get_time(date_img_D)
current_D = get_M_secs( time_D )
current_diff = current - current_D
print (current_T)
print (last_time)
print (time_D)
STOPFLAG = True
lastFrame = cv2.resize(lastFrame,(853, 480))
cv2.imshow('frame2',lastFrame)
cv2.waitKey(4000)
video_d.release()
# pics = []
# for k in range(5):
# ret, frame = video.read()
# pics.append(frame)
#else:
#print ('Земля')
else:
break
inn = cv2.waitKey(1) & 0xFF
if inn == ord('q'):
break
i += 1
video.release()
cv2.destroyAllWindows()
video = cv2.VideoCapture('video/2268-video.mp4') #759
video_d = cv2.VideoCapture('video/2269-video.mp4')
video_d.get(cv2.CAP_PROP_FRAME_COUNT)