-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
67 lines (50 loc) · 1.93 KB
/
server.py
File metadata and controls
67 lines (50 loc) · 1.93 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
import rpyc
import cv2
from CountsPerSec import CountsPerSec
from VideoGet import VideoGet
from VideoShow import VideoShow
from FaceThread import FaceThread
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
class MyService(rpyc.Service):
def on_connect(self, conn):
print("Client Connected")
def putIterationsPerSec(frame, iterations_per_sec):
cv2.putText(frame, "{:.0f} iterations/sec".format(iterations_per_sec),
(10, 450), cv2.FONT_HERSHEY_SIMPLEX, 1.0, (255, 255, 255))
return frame
def exposed_threadBoth(self,source=0):
video_getter = VideoGet(source).start()
face_thread = FaceThread(video_getter.frame, face_cascade).start()
# video_shower = VideoShow(video_getter.frame).start()
cps = CountsPerSec().start()
frames = []
count = 0
while True:
if video_getter.stopped or face_thread.stopped:
# video_shower.stop()
video_getter.stop()
face_thread.stop()
break
frame = video_getter.frame
face_thread.frame = frame
# frame = putIterationsPerSec(frame, cps.countsPerSec())
# video_shower.frame = face_thread.frame
cps.increment()
img_encoded = cv2.imencode('.jpg', face_thread.frame)[1].tostring()
frames.append(img_encoded)
count=count+1
if count == 500:
break
return frames
def exposed_readImage(self):
img = cv2.imread("faces.jpg")
img_encoded = cv2.imencode('.jpg', img)[1].tostring()
return img_encoded
def on_disconnect(self, conn):
print("Client disconnected")
if __name__ == "__main__":
from rpyc.utils.server import ThreadedServer
server = ThreadedServer(MyService, port=18861, protocol_config={
'allow_public_attrs': True,
})
server.start()