-
Notifications
You must be signed in to change notification settings - Fork 8
/
rapid_streaming_zmq.py
43 lines (35 loc) · 1.05 KB
/
rapid_streaming_zmq.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'''Streams video from the robot using ZeroMQ.
This example uses a Raspberry Pi camera and requires the following libraries to
be installed on the Raspberry Pi:
- https://picamera.readthedocs.org/en/release-1.10/
- http://zeromq.org/
'''
import io
import socket
import struct
import time
import picamera
import zmq
# Setup ZeroMQ PUBLISH socket
context = zmq.Context()
zmq_socket = context.socket(zmq.PUB)
zmq_socket.bind("tcp://0.0.0.0:5557")
try:
with picamera.PiCamera() as camera:
camera.resolution = ((64, 64))
camera.framerate = 30
time.sleep(2)
start = time.time()
# Keep track of frames sent to calculate actual frame rate
n = 0
stream = io.BytesIO()
# Capture from the video port
for foo in camera.capture_continuous(stream, 'jpeg',
use_video_port=True):
stream.seek(0)
zmq_socket.send(stream.read())
n += 1
stream.seek(0)
stream.truncate()
finally:
pass