imagezmq is a set of Python classes that transport OpenCV images from one computer to another using PyZMQ messaging. For example, here is a screen on a Mac computer showing simultaneous video streams from 8 Raspberry Pi cameras:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# zmqimage.py -- classes to send, receive and display cv2 images via zmq | |
# based on serialization in pyzmq docs and pyzmq/examples/serialization | |
''' | |
PURPOSE: | |
These classes allow a headless (no display) computer running OpenCV code | |
to display OpenCV images on another computer with a display. | |
For example, a headless Raspberry Pi with no display can run OpenCV code | |
and can display OpenCV images on a Mac with a display. | |
USAGE: |
The test programs show how imagezmq can be used to capture images on Raspberry Pi computers, send them to a Mac via imagezmq and then display them on the Mac. The ability for one hub to gather and process images from multiple sources allows computer vision pipelines to distribute vision processing across multiple computers.
The API for imagezmq consists of 2 classes with 2 methods each. The ImageSender class has 2 methods: one for sending an OpenCV image and one for sending a jpg compressed OpenCV image. The ImageHub class has 2 methods: one for receiving an OpenCV image and one for receiving a jpg compressed OpenCV image.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#imagenode.py snippet | |
# (all the imports, logging setup hidden for now) | |
settings = Settings() # get settings for node cameras, ROIs, GPIO | |
node = ImageNode(settings) # start ZMQ, cameras and other sensors | |
# forever event loop | |
while True: | |
node.get_sensor_data() # grab camera images and other sensor data | |
node.process_sensor_data() # detect motion, etc. | |
while len(node.msg_q) > 0: | |
try: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""test sending a jpg buffer and check type & size of buffer | |
A simple test program that creates an image, then converts it to a | |
jpg_buffer and checks the type(), ndim, size and shape of the jpg_buffer. | |
This program tests some imports and some OpenCV functions, as well. | |
Open Source Licensed under MIT License (MIT) | |
Copyright (c) 2020, Jeff Bass, [email protected] | |
""" |
OlderNewer