From 559fe7f09d656724e6f29ebb03d839cb41cd6f12 Mon Sep 17 00:00:00 2001 From: Lennart Heimbs Date: Sun, 4 Aug 2019 16:29:57 +0200 Subject: [PATCH] start work Video stream from pi to faster pc --- camera/video_client_pi.py | 45 ++++++++++++++++++++++++++++++++++ camera/video_client_pi_cv2.py | 46 +++++++++++++++++++++++++++++++++++ camera/video_server.py | 34 ++++++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 camera/video_client_pi.py create mode 100644 camera/video_client_pi_cv2.py create mode 100644 camera/video_server.py diff --git a/camera/video_client_pi.py b/camera/video_client_pi.py new file mode 100644 index 0000000..c80a1d1 --- /dev/null +++ b/camera/video_client_pi.py @@ -0,0 +1,45 @@ +import io +import socket +import struct +import time +import picamera + +# Connect a client socket to my_server:8000 (change my_server to the +# hostname of your server) +client_socket = socket.socket() +client_socket.connect(('my_server', 8000)) + +# Make a file-like object out of the connection +connection = client_socket.makefile('wb') +try: + with picamera.PiCamera() as camera: + camera.resolution = (640, 480) + # Start a preview and let the camera warm up for 2 seconds + camera.start_preview() + time.sleep(2) + + # Note the start time and construct a stream to hold image data + # temporarily (we could write it directly to connection but in this + # case we want to find out the size of each capture first to keep + # our protocol simple) + start = time.time() + stream = io.BytesIO() + for foo in camera.capture_continuous(stream, 'jpeg'): + # Write the length of the capture to the stream and flush to + # ensure it actually gets sent + connection.write(struct.pack(' 30: + break + # Reset the stream for the next capture + stream.seek(0) + stream.truncate() + # Write a length of zero to the stream to signal we're done + connection.write(struct.pack(' 30: + break + # Reset the stream for the next capture + stream.seek(0) + stream.truncate() + # Write a length of zero to the stream to signal we're done + connection.write(struct.pack('