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.

33 lines
699 B

  1. import cv2
  2. import io
  3. import socket
  4. import struct
  5. import time
  6. import pickle
  7. import zlib
  8. client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  9. client_socket.connect(('127.0.0.1', 8486))
  10. connection = client_socket.makefile('wb')
  11. cam = cv2.VideoCapture(1)
  12. cam.set(3, 320);
  13. cam.set(4, 240);
  14. img_counter = 0
  15. encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 90]
  16. while True:
  17. ret, frame = cam.read()
  18. result, frame = cv2.imencode('.jpg', frame, encode_param)
  19. # data = zlib.compress(pickle.dumps(frame, 0))
  20. data = pickle.dumps(frame, 0)
  21. size = len(data)
  22. print("{}: {}".format(img_counter, size))
  23. client_socket.sendall(struct.pack(">L", size) + data)
  24. img_counter += 1
  25. cam.release()