This repository was archived by the owner on Apr 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverVideo.py
More file actions
56 lines (49 loc) · 1.33 KB
/
serverVideo.py
File metadata and controls
56 lines (49 loc) · 1.33 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
import cv2
import numpy as np
import sys
import time
import socket
import pickle
print("[*]Initializing socket for Video")
# video socket
soc=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
print("[*]Initializing webcam for Video")
#initilizing webcam for videosocket
video=cv2.VideoCapture(0)
print("[*]Initializtion of webcam access succed\n")
# connecting to video socket at 8080
print("[*] Creating open socket server at 8080 port for video")
soc.bind(('0.0.0.0',8080))
soc.listen(5)
conn,addr=soc.accept()
print("[*] Connected \n\n")
def recvVideo():
global conn
while 1:
try:
data=b""
length=0
while length<921764:
pac=conn.recv(9999999)
length+=len(pac)
data+=pac
if data[0:1]==b'a':
frame1=pickle.loads(data[1::])
cv2.imshow("frame1",frame1)
key=cv2.waitKey(1)
if key == 27:
break
except KeyboardInterrupt:
sys.exit()
def sendVideo():
global conn,video
while 1:
try:
_,frame=video.read()
img_data=np.array(frame)
data=pickle.dumps(img_data)
conn.send(b"b"+data)
except KeyboardInterrupt:
video.release()
sys.exit()
cv2.destroyAllWindows()