-
-
Save AyushBhat822/0925190b85426615ec10a2bc6e0517c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket, cv2, pickle,struct | |
# Socket Create | |
server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) | |
host_name = socket.gethostname() | |
host_ip = socket.gethostbyname(host_name) | |
print('HOST IP:',host_ip) | |
port = 9999 | |
socket_address = (host_ip,port) | |
# Socket Bind | |
server_socket.bind(socket_address) | |
# Socket Listen | |
server_socket.listen(1) | |
print("LISTENING AT:",socket_address) | |
# Socket Accept | |
while True: | |
client_socket,addr = server_socket.accept() | |
print('GOT CONNECTION FROM:',addr) | |
if client_socket: | |
vid = cv2.VideoCapture(0) | |
while(vid.isOpened()): | |
ret,image = vid.read() | |
img_serialize = pickle.dumps(image) | |
message = struct.pack("Q",len(img_serialize))+img_serialize | |
client_socket.sendall(message) | |
cv2.imshow('VIDEO FROM SERVER',image) | |
key = cv2.waitKey(10) | |
if key ==13: | |
client_socket.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment