You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
989 B

  1. import socket
  2. import sys
  3. import cv2
  4. import pickle
  5. import numpy as np
  6. import struct ## new
  7. import zlib
  8. HOST=''
  9. PORT=8486
  10. s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  11. print('Socket created')
  12. s.bind((HOST,PORT))
  13. print('Socket bind complete')
  14. s.listen(10)
  15. print('Socket now listening')
  16. conn,addr=s.accept()
  17. data = b""
  18. payload_size = struct.calcsize(">L")
  19. print("payload_size: {}".format(payload_size))
  20. while True:
  21. while len(data) < payload_size:
  22. print("Recv: {}".format(len(data)))
  23. data += conn.recv(4096)
  24. print("Done Recv: {}".format(len(data)))
  25. packed_msg_size = data[:payload_size]
  26. data = data[payload_size:]
  27. msg_size = struct.unpack(">L", packed_msg_size)[0]
  28. print("msg_size: {}".format(msg_size))
  29. while len(data) < msg_size:
  30. data += conn.recv(4096)
  31. frame_data = data[:msg_size]
  32. data = data[msg_size:]
  33. frame=pickle.loads(frame_data)
  34. frame = cv2.imdecode(frame, cv2.IMREAD_COLOR)
  35. cv2.imshow('ImageWindow',frame)
  36. if cv2.waitKey(1) & 0xFF == ord('q'):
  37. break