-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathRunCamera.py
194 lines (151 loc) · 5.99 KB
/
RunCamera.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
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import cv2
import numpy as np
import zmq
from System.Data.CONSTANTS import *
from System.CameraNode import CameraNode
import random
vidpath = ''
cities = ['Cairo', 'Alexandria', 'Gizah', 'Shubra El-Kheima', 'Port Said', 'Suez', 'Luxor', 'Al-Mansura',
'Tanta', 'Asyut', 'Ismailia', 'Fayyum', 'Zagazig', 'Aswan', 'Damietta',
'Damanhur', 'Al-Minya', 'Beni Suef', 'Qena', 'Sohag', 'Hurghada', 'Shibin El Kom',
'Banha', 'Arish', 'Mallawi', 'Bilbais', 'Marsa Matruh',
'Idfu, Mit Ghamr', 'Al-Hamidiyya', 'Desouk', 'Qalyub', 'Abu Kabir', 'Girga', 'Akhmim', 'Matareya']
class Button(QPushButton):
def __init__(self, title, parent):
super().__init__(title, parent)
self.setAcceptDrops(True)
def dragEnterEvent(self, e):
m = e.mimeData()
if m.hasUrls():
e.accept()
else:
e.ignore()
def dropEvent(self, e):
global vidpath
m = e.mimeData()
if m.hasUrls():
# self.parent().label.setPixmap(QPixmap(m.urls()[0].toLocalFile()))
self.parent().loadVideo(m.urls()[0].toLocalFile())
vidpath = m.urls()[0].toLocalFile()
print(m.urls()[0].toLocalFile())
class Client(QWidget):
def __init__(self, port=MASTERPORT, ip=MASTERIP):
super().__init__()
self.setWindowTitle('Argus - Camera Node')
self.setWindowIcon(QIcon('UI/icon.png'))
self.setGeometry(350, 90, 629, 597)
self.setFixedSize(615, 419)
self.processing_lable = self.make_lable('Processing....', 0, 0, 40, 40, True, 12)
self.processing_lable.setVisible(False)
self.gif = QMovie('UI/loading.gif')
self.gif.setScaledSize(QSize().scaled(40, 40, Qt.KeepAspectRatio))
self.processing_lable.setMovie(self.gif)
self.gif.start()
self.select_vid = Button("", self)
self.select_vid.setText('Select video')
self.select_vid.move(170, 20)
self.select_vid.resize(91,71)
self.select_vid.clicked.connect(self.getfiles)
font = QFont('SansSerif', 9)
font.setBold(True)
self.select_vid.setFont(font)
self.play_vid = QPushButton(self)
self.play_vid.setStyleSheet("background-color: #000000;")
self.play_vid.setText('')
self.play_vid.move(30, 105)
self.play_vid.resize(559, 300)
self.play_vid.clicked.connect(self.playVideo)
process = QPushButton(self)
process.setText('Process')
process.move(350, 20)
process.resize(91,71)
process.clicked.connect(self.sendToBk)
process.setFont(font)
# Initialize connection
context = zmq.Context()
print("Connecting to server...")
self.socket = context.socket(zmq.REQ)
self.socket.connect("tcp://"+ip+":"+str(port))
def sendToBk(self):
global vidpath, cities
if vidpath=='':
return
self.processing_lable.setVisible(True)
video_id = vidpath.split('.')[0]
video_id = video_id.split('/')
video_id = int(video_id[-1])
print("hello")
CameraNode(video_id, 'videos/' + str(video_id) + '.mp4',files=Work_Detect_Files, city= random.choice(cities), district_no= 'District ' + str(random.randint(1, 30))).start()
self.playVideo()
def playVideo(self):
global vidpath
print(vidpath)
if vidpath=='':
return
cap = cv2.VideoCapture(vidpath)
if (cap.isOpened() == False):
print("Error opening video file")
while (cap.isOpened()):
ret, frame = cap.read()
if ret == True:
cv2.imshow('Frame', frame)
if cv2.waitKey(25) & 0xFF == ord('q'):
break
else:
break
cap.release()
cv2.destroyAllWindows()
def getfiles(self):
global vidpath
fileName, _ = QFileDialog.getOpenFileName(self, 'Single File', 'C:\'', '*.mp4 *.mkv *.avi')
if fileName=='':
return
self.loadVideo(path=fileName)
vidpath = fileName
print(vidpath,'vid')
print(fileName)
def loadVideo(self, path='h.mp4'):
cap = cv2.VideoCapture(path)
ret, frame = cap.read()
img = cv2.resize(frame, (351, 241), interpolation=cv2.INTER_AREA)
button = cv2.imread('UI/Play-Button-PNG-Picture.png')
button = cv2.resize(button, (111, 111), interpolation=cv2.INTER_AREA)
print(button.shape)
print(img.shape)
height_needed = 241 - button.shape[0]
width_needed = 351 - button.shape[1]
top = int(np.floor(height_needed / 2))
bottom = int(np.ceil(height_needed / 2))
left = int(np.floor(width_needed / 2))
right = int(np.ceil(width_needed / 2))
border = cv2.copyMakeBorder(button, top=top, bottom=bottom, left=left, right=right, borderType=cv2.BORDER_CONSTANT, value=0)
border = np.where(border < 150, img, border)
border = cv2.resize(border, (559, 300), interpolation=cv2.INTER_AREA)
cv2.imwrite('UI/tempToLoad.png', border)
# self.select_vid.setVisible(False)
# play_vid = QPushButton(self)
# self.play_vid.setText('')
# self.play_vid.move(140, 20)
# self.play_vid.resize(351, 241)
self.play_vid.setStyleSheet("background-image : url(UI/tempToLoad.png);")
# self.play_vid.clicked.connect(self.playVideo)
# self.play_vid.setVisible(True)
def make_lable(self, text, x, y, width, height, bold=False, font=12):
label = QLabel(self)
label.setText(text)
label.move(x, y)
label.resize(width, height)
font = QFont('SansSerif', font)
if bold:
font.setBold(True)
label.setFont(font)
return label
if __name__ == "__main__":
app = QApplication(sys.argv)
form = Client()
form.show()
sys.exit(app.exec_())