-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.py
More file actions
246 lines (225 loc) · 9.68 KB
/
Copy pathmain.py
File metadata and controls
246 lines (225 loc) · 9.68 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
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import os,sys, cv2, threading as thr
import numpy as np
from time import sleep
opencv_name = []
picture_number = 0
# First Initialization
path = os.getcwd()
def firs_i():
cam_lst = []
try:
total_cam=int(input('Pleas Enter number of camera:'))
except:
print('you must enter a number\n\n Script Exit soon')
exit()
for i in range(total_cam):
cam=input("Camera number %s\n\n Pleas Enter RTSP URL:\n" %i)
if cam is not "":
cam_lst.append(cam)
co=input("\n\n\nyou entred %s Camera for Monitoring if its correct, then type 'yes' to continue or pressess Enter to Exit.\n:" % str(total_cam))
if co=='yes' or co=='Yes' or co=='YES':
for i in cam_lst: print(i)
else:
exit()
#write CAM-LIST to a file:
cam_file=open("camfile.txt",'w+')
for i in cam_lst:
cam_file.writelines(i + '\n')
print("\n[+]New Cam Setting Saved.[\n]%s\n\n" % i)
cam_file.close()
print("Initialization was finished successfully.\n" )
input('Press Enter to continue...\n')
#------------------------------------------------CHeck Already Initialized or not ---------------------------------
if os.path.isfile('camfile.txt') !=True:
firs_i()
#*********************************************** Main Defination for RTSP view *********************************************************
#---------------------------------------------------------------------------------------------------------------------------------------
#*********************************************** Main Defination for RTSP view *********************************************************
#---------------------------------------------------------------------------------------------------------------------------------------
#*********************************************** Main Defination for RTSP view *********************************************************
#---------------------------------------------------------------------------------------------------------------------------------------
def view_cam(rtsp_lst,title,x=100,y=100):
vid1,vid2,vid3,vid4,vid5=cv2.VideoCapture(''),cv2.VideoCapture(''),cv2.VideoCapture(''),cv2.VideoCapture(''),cv2.VideoCapture('')
last_frame=[]
p=0
#Read and Capture Streams
for i in rtsp_lst:
print('\nNew Camera Initialization....' )
sleep(1)
if 'rtsp' in i:
if p==0:
vid1=cv2.VideoCapture(i)
if p==1:
vid2=cv2.VideoCapture(i)
if p==2:
vid3=cv2.VideoCapture(i)
if p==3:
vid4=cv2.VideoCapture(i)
if p==4:
vid5=cv2.VideoCapture(i)
p +=1
#---------------------Refreash Frames ----------------------
while 1:
if vid1.isOpened():
chk,frm=vid1.read()
if chk ==True:
last_frame.append(cv2.resize(frm,(x,y)))
if vid2.isOpened():
chk,frm=vid2.read()
if chk ==True:
last_frame.append(cv2.resize(frm,(x,y)))
if vid3.isOpened():
chk,frm=vid3.read()
if chk ==True:
last_frame.append(cv2.resize(frm,(x,y)))
#-----------VID4
if vid4.isOpened():
chk,frm=vid4.read()
if chk ==True:
last_frame.append(cv2.resize(frm,(x,y)))
#------------VID5
if vid5.isOpened():
chk,frm=vid5.read()
if chk ==True:
last_frame.append(cv2.resize(frm,(x,y)))
# ************************************************* *********************
# ************************************************* *********************
# ************************************************* *********************
#****************************************************END of refresh all 5 item video show*********************
# ************************************************* *********************
# ************************************************* *********************
# ************************************************* *********************
# Single view Definition with number
def single_view(cn):
#****************************************************************
#******************* Destroy each window created ****************
# ****************************************************************
#
def wr_img(f_name,frame):
#
global picture_number
picture_number += 1
cv2.imwrite('capture\\%s.jpg' % picture_number, frame)
if cn ==ord('1'):
cv2.destroyAllWindows()
while 1:
if vid1.isOpened():
chk1,frm1=vid1.read()
if chk1==True:
cv2.imshow('Camera-1',frm1)
key=cv2.waitKey(1)
if key==27:
cv2.destroyWindow('Camera-1')
#main_exec()
break
if key==ord('c'):
wr_img('Camera1-%s'%picture_number,frm1)
if cn ==ord('2'):
cv2.destroyAllWindows()
while 1:
if vid2.isOpened():
chk,frm = vid2.read()
if chk == True:
cv2.imshow('Camera-2', frm)
key = cv2.waitKey(1)
if key == 27:
cv2.destroyWindow('Camera-2')
# main_exec()
break
if key == ord('c'):
wr_img('Camera2-%s'%picture_number, frm)
if cn == ord('3'):
cv2.destroyAllWindows()
while 1:
if vid3.isOpened():
chk, frm=vid3.read()
if chk == True:
cv2.imshow('Camera-3', frm)
key=cv2.waitKey(1)
if key == 27:
cv2.destroyWindow('Camera-3')
# main_exec()
break
if key == ord('c'):
wr_img('Camera3-%s'%picture_number,frm)
if cn == ord('4'):
cv2.destroyAllWindows()
while 1:
if vid4.isOpened():
chk, frm = vid4.read()
if chk == True:
cv2.imshow('Camera-4', frm)
key=cv2.waitKey(1)
if key == 27:
cv2.destroyWindow('Camera-4')
# main_exec()
break
if key==ord('c'):
wr_img('Camera4-%s'%picture_number,frm)
if cn ==ord('5'):
cv2.destroyAllWindows()
while 1:
if vid5.isOpened():
chk,frm=vid5.read()
if chk==True:
cv2.imshow('Camera-5',frm)
key=cv2.waitKey(1)
if key==27:
#exit()
cv2.destroyWindow('Camera-5')
#main_exec()
break
if key==ord('c'):
wr_img('Camera5-%s'%picture_number,frm)
#--------Create Merge frame
frame_np=np.concatenate(last_frame,axis=1)
cv2.imshow(title,frame_np)
last_frame=[]
key=cv2.waitKey(1)
if key == 27:
cv2.destroyWindow(title)
quit()
single_view(key)
#*************///////////////////\\\\\\\\\\\\\\\\ END of Main defination **********************************
def main_exec():
#
#
# ----------Read stream address from file
# ------------------------------------------Check file exist
if os.path.isfile('camfile.txt') == False:
quit()
#
#
file_cam = open('camfile.txt', 'r')
list_camfile = file_cam.readlines()
lst_camf_no_ent = []
for i in list_camfile:
lst_camf_no_ent.append(i.split('\n')[0])
# -----------Split 5 item for send to show list and START IT.
#***********************************************************************************///////////\\\\\\\
five_item = []
#
cam_num = 0
gr_num = 0
for i in lst_camf_no_ent:
gr_num += 1
if len(five_item) < 5:
five_item.append(i)
#
if len(five_item) == 5:
tr_view = thr.Thread(target=view_cam, args=(five_item,'CamGR%s' %cam_num, ), name='Group-%s' % gr_num)
tr_view.start()
# view_cam(five_item)
five_item = []
cam_num += 1
continue
#
#
#
if cam_num+1 == len(lst_camf_no_ent):
#
gr_num += 1
tr_view = thr.Thread(target=view_cam, args=(five_item, 'Camera Groupw %s' % gr_num, ))
tr_view.start()
cam_num += 1
main_exec()