-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebcam-server.py
More file actions
45 lines (32 loc) · 955 Bytes
/
webcam-server.py
File metadata and controls
45 lines (32 loc) · 955 Bytes
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
from configparser import Interpolation
import cv2
import socket
import pickle
port = 8084
#open webcam
cap = cv2.VideoCapture(0)
#verify if the webcam has been open
if not cap.isOpened():
raise IOError("problem to acess the webcam")
#object Socket
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#associa the socket for a port
server.bind("0.0.0.0",port)
server.listen()
#server keep waiting connection
while True:
print(f"***Server waiting in the port {port}***")
#accept the connection
conn, addr = server.accept()
print(f"== connection received OF {addr} ==")
#capture a frame
ret,frame = cap.read()
#change size of frame
frame = cv2.resize(frame,None, fx=0.5,fy=0.5,interpolation = cv2.INTER_AREA)
#pack the frame
dados = pickle.dumps(frame)
#send the frames's pack
conn.send(dados)
#close the connection
conn.close()
print("== client disconnected == ")