Smart-Home am Beispiel der Präsenzerkennung im Raum Projektarbeit Lennart Heimbs, Johannes Krug, Sebastian Dohle und Kevin Holzschuh bei Prof. Oliver Hofmann SS2019
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.

video_server.py 1.1KB

12345678910111213141516171819202122232425262728293031323334
  1. import io
  2. import socket
  3. import struct
  4. from PIL import Image
  5. # Start a socket listening for connections on 0.0.0.0:8000 (0.0.0.0 means
  6. # all interfaces)
  7. server_socket = socket.socket()
  8. server_socket.bind(('0.0.0.0', 8000))
  9. server_socket.listen(0)
  10. # Accept a single connection and make a file-like object out of it
  11. connection = server_socket.accept()[0].makefile('rb')
  12. try:
  13. while True:
  14. # Read the length of the image as a 32-bit unsigned int. If the
  15. # length is zero, quit the loop
  16. image_len = struct.unpack('<L', connection.read(struct.calcsize('<L')))[0]
  17. if not image_len:
  18. break
  19. # Construct a stream to hold the image data and read the image
  20. # data from the connection
  21. image_stream = io.BytesIO()
  22. image_stream.write(connection.read(image_len))
  23. # Rewind the stream, open it as an image with PIL and do some
  24. # processing on it
  25. image_stream.seek(0)
  26. image = Image.open(image_stream)
  27. print('Image is %dx%d' % image.size)
  28. image.verify()
  29. print('Image is verified')
  30. finally:
  31. connection.close()
  32. server_socket.close()