Facebook
From Mammoth Bison, 4 Years ago, written in Python.
Embed
Download Paste or View Raw
Hits: 144
  1. import cv2
  2. import io
  3. import socket
  4. import struct
  5. import time
  6. import pickle
  7. import zlib
  8.  
  9. client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  10. client_socket.connect(('192.168.1.165', 8485))
  11. connection = client_socket.makefile('wb')
  12.  
  13. cam = cv2.VideoCapture(0)
  14.  
  15. cam.set(3, 320);
  16. cam.set(4, 240);
  17.  
  18. img_counter = 0
  19.  
  20. encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 90]
  21.  
  22. while True:
  23.     ret, frame = cam.read()
  24.     result, frame = cv2.imencode('.jpg', frame, encode_param)
  25. #    data = zlib.compress(pickle.dumps(frame, 0))
  26.     data = pickle.dumps(frame, 0)
  27.     size = len(data)
  28.  
  29.  
  30.     print("{}: {}".format(img_counter, size))
  31.     client_socket.sendall(struct.pack(">L", size) + data)
  32.     img_counter += 1
  33.  
  34. cam.release()