imagezmq

A set of Python classes that transport OpenCV images from one computer to another using PyZMQ messaging.

https://github.com/jeffbass/imagezmq

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (8.7%) to scientific vocabulary

Keywords

imagezmq opencv-python python pyzmq raspberry-pi
Last synced: 4 months ago · JSON representation ·

Repository

A set of Python classes that transport OpenCV images from one computer to another using PyZMQ messaging.

Basic Info
  • Host: GitHub
  • Owner: jeffbass
  • License: mit
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 1.53 MB
Statistics
  • Stars: 1,049
  • Watchers: 36
  • Forks: 163
  • Open Issues: 34
  • Releases: 3
Topics
imagezmq opencv-python python pyzmq raspberry-pi
Created almost 8 years ago · Last pushed over 1 year ago
Metadata Files
Readme Changelog Contributing License Code of conduct Citation Security

README.rst

====================================
imageZMQ: Transporting OpenCV images
====================================

Introduction
============

**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 image streams from 8 Raspberry Pi cameras:

.. image:: docs/images/screenshottest.png

Using **imageZMQ**, this is possible with 11 lines of Python on each Raspberry
Pi and with 8 lines of Python on the Mac.

First, run this receiver program on the Mac (or other display computer):

.. code-block:: python

    # run this program on the Mac to display image streams from multiple RPis
    import cv2
    import imagezmq
    image_hub = imagezmq.ImageHub()
    while True:  # show streamed images until Ctrl-C
        rpi_name, image = image_hub.recv_image()
        cv2.imshow(rpi_name, image) # 1 window for each RPi
        cv2.waitKey(1)
        image_hub.send_reply(b'OK')


Then, on each Raspberry Pi, run this sender program:

.. code-block:: python

    # run this program on each RPi to send a labelled image stream
    # you can run it on multiple RPi's; 8 RPi's running in above example
    import socket
    import time
    from picamera2 import Picamera2
    import imagezmq

    sender = imagezmq.ImageSender(connect_to='tcp://jeff-macbook:5555')

    rpi_name = socket.gethostname() # send RPi hostname with each image
    picam = Picamera2()
    picam.start()
    time.sleep(2)  # allow camera sensor to warm up
    while True:  # send images as stream until Ctrl-C
        image = picam.capture_array()
        sender.send_image(rpi_name, image)


Wow! A video surveillance system with 8 (or more!) Raspberry Pi cameras in
19 lines of Python.

See `About the multiple RPi video streaming examples `_
for more details about this example.

.. contents::

Why use imageZMQ?
=================

**imageZMQ** is an easy to use image transport mechanism for a distributed image
processing network. For example, a network of a dozen Raspberry Pis with cameras
can send images to a more powerful central computer. The Raspberry Pis perform
image capture and simple image processing like flipping, blurring and motion
detection. Then the images are passed via **imageZMQ** to the central computer for
more complex image processing like image tagging, text extraction, feature
recognition, etc. An example of using **imageZMQ** can be found
at `Using imageZMQ in distributed computer vision projects `_.

Each **imageZMQ** message is a ``(text_message, image)`` tuple. The text 
portion of the tuple identifies the source and other info about the image. In 
the example above, the ``text_message`` portion identifies which RPi is sending the
the image so that the receiver can put each unique RPi image stream into a
specific window. More details about the **imageZMQ** tuples in the above example
are `here `_.

Features
========

- Sends OpenCV images from one computer to another using ZMQ.
- Can send jpeg compressed OpenCV images, to lighten network loads.
- Uses the powerful ZMQ messaging library through PyZMQ bindings.
- Allows a choice of 2 different ZMQ messaging patterns (REQ/REP or PUB/SUB).
- Enables the image hub to receive and process images from multiple image senders
  simultaneously. 

Why ZMQ? Why not some other messaging protocol?
===============================================

There are a number of high quality and well maintained messaging protocols for
passing messages between computers. I looked at MQTT, RabbitMQ, AMQP and ROS as
alternatives. I chose ZMQ and its Python PyZMQ bindings for several reasons:

- ZMQ does not require a message broker. It is a peer to peer protocol that does
  not need to pass an image first to a message broker and then to the imagehub.
  This means fewer running processes and less “double handling” of images.
  OpenCV images are large compared to simple text messages, so the absence of a
  message broker is important.
- ZMQ is very fast for passing OpenCV images. It enables high throughput between
  image senders and image hubs.
- ZMQ and its PyZMQ bindings are easy to install.

**imageZMQ** has been transporting images from a dozen Raspberry Pi computers
scattered around my farm to 2 linux image hub servers for over 5
years. The RPi's capture and send dozens to thousands of frames frames a day.
**imageZMQ** has worked very reliably and is very fast. You can learn more about
my "science experiment urban permaculture farm" project at
`Yin Yang Ranch project overview. `_


Messaging Patterns: REQ/REP versus PUB/SUB
==========================================

ZMQ allows many different messaging patterns. Two are implemented in **imageZMQ**:

- REQ/REP: Each RPi sends an image and waits for a REPLY from the central image
  hub. The RPi sends a new image only when the REPLY is received. In the REQ/REP
  messaging pattern, each image sender must await a REPLY before continuing. It is a
  "blocking" pattern for the sender.
- PUB/SUB: Each RPi sends an image, but does not expect a REPLY from the central
  image hub. It can continue sending images without awaiting any acknowledgement
  from the image hub. The image hub provides no REPLY. It is a "non-blocking"
  pattern for the sender.

There are advantages and disadvantages for each pattern. For further details,
see: `REQ/REP versus PUB/SUB Messaging Patterns `_.
**REQ/REP is the default.**


Dependencies and Installation
=============================

+--------------+--------+---------------+-----------+-------+
| |pyversions| | |pypi| | |releasedate| | |license| | |doi| |
+--------------+--------+---------------+-----------+-------+

.. |pyversions| image:: /docs/images/python_versions.svg
   :target: https://pypi.org/project/imagezmq/

.. |pypi| image:: /docs/images/pypi_version.svg
   :target: https://pypi.org/project/imagezmq/

.. |releasedate| image:: /docs/images/release_date.svg
   :target: https://github.com/jeffbass/imagezmq/tree/v.1.2.0

.. |license| image::  /docs/images/license.svg
   :target: LICENSE.txt

.. |doi| image::  /docs/images/doi.svg
   :target: https://zenodo.org/records/12770292

**imageZMQ** has been tested with:

- Python 3.5, 3.6, 3.7, 3.8, 3.9, 3.10 and 3.11
- PyZMQ 16.0, 17.1, 19.0 and 26.0
- Numpy 1.13, 1.16, 1.18 and 1.24
- OpenCV 3.3, 4.0, 4.1 and 4.6
- Raspberry Pi OS Bookworm and Bullseye using PiCamera2
- Raspbian OS Buster, Stretch and Raspbian Jessie using legacy PiCamera

OpenCV can be challenging to install. There are many example tutorials on the web. 
For Raspberry Pi computers with current Raspberry Pi OS versions, the Picamera2 
documentation recommends installing OpenCV using apt. 

Be sure to install OpenCV, including Numpy, into a Python Virtual Environment.
Be sure to install **imageZMQ** into the **same** virtual environment. For
example, on a Raspberry Pi running Raspberry Pi OS Bookworm, my virtual
environment is named **py311cv4**.

Install **imageZMQ** using pip:

.. code-block:: bash

    workon py311cv4  # use your virtual environment name
    pip install imagezmq

**imageZMQ** has a directory of tests organized into sender and receiver pairs.
You will get the "tests" directory containing all the test programs by
cloning the GitHub repository:

.. code-block:: bash

    git clone https://github.com/jeffbass/imagezmq.git

Once you have cloned the imagezmq directory to a directory on your local machine,
you can run the tests per the instructions below. You can use imageZMQ in your
own code by importing it (``import imagezmq``).

**imageZMQ** and all of the software dependencies must be installed on the
display computer that will be receiving the images AND it must all be installed
on every Raspberry Pi that will be sending images. If you will be using multiple
Raspberry Pis to capture and send images it is may be helpful to install the
software on a single Raspberry Pi and test it using the tests below. Once all
the tests have run successfully, clone the SD card as needed to use the software
on multiple Raspberry Pis.

Running the Tests to verify **imageZMQ** is working
===================================================

After you have installed **imageZMQ** you will want to verify that it installed
correctly. The best way to do this is to run some of the test programs that are 
in the ``tests`` folder. The most basic test is a matched pair of sending and
receiving programs. The sender program creates a series of OpenCV numbered
images and sends them via **imageZMQ**. The receiving program displays the
numbered images. You can run both of these programs on the same computer first, 
then run them on 2 different computers on the same network. This will confirm
that **imageZMQ** installed correctly and that you are able to specify and open 
ports for transferring OpenCV images between computers. 

There are also test programs that send images from cameras:

1. Raspberry Pi camera module using the PiCamera2 library with Raspberry Pi OS
2. Webcam or USB camera using OpenCV's cv2.VideoCapture to capture images

The Picamera2 library requires Raspberry Pi OS Bullseye or later. There are also
some test programs that use the original Picamera library for older Raspberry Pi
OS versions (Buster and older).

Further details are in `Running the Test Programs `_.

Additional Documentation and Examples
=====================================
- `API and Two Simple Example Programs `_
- `More details about the multiple RPi video streaming example `_
- `Running the Test Programs `_
- `REQ/REP versus PUB/SUB Messaging Patterns `_
- `Examples showing different techniques for using imageZMQ `_
- `Using imageZMQ in distributed computer vision projects `_
- `FAQ: Frequently Asked Questions `_
- How **imageZMQ** is used in my own projects connecting multiple
  Raspberry Pi **imagenodes** to an **imagehub**:

  - My Yin Yang Ranch project to manage a small urban permaculture farm:
    `Yin Yang Ranch project overview `_
  - `imagenode: Capture and Send Images and Sensor Data `_
  - `imagehub: Receive and Store Images and Event Logs `_


I gave a talk about imageZMQ and its use in my Yin Yang Ranch project at
PyCon 2020:
**Jeff Bass - Yin Yang Ranch: Building a Distributed Computer
Vision Pipeline using Python, OpenCV and ZMQ**

`PyCon 2020 Talk Video about the project  `_

`PyCon 2020 Talk Presentation slides  `_

Contributing
============
**imageZMQ** is still in active development. I welcome open issues and
pull requests, but because the programs are still evolving, it is best to
open an issue for some discussion before submitting pull requests. We can
exchange ideas about your potential pull request and open a development branch
where you can develop your code and get feedback and testing help from myself
and others. **imageZMQ** is used in my own long running projects and the
projects of others, so backwards compatibility with the existing API is
important.

Contributors
============
Thanks for all contributions big and small. Some significant ones:

+------------------------+-----------------+----------------------------------------------------------+
| **Contribution**       | **Name**        | **GitHub**                                               |
+------------------------+-----------------+----------------------------------------------------------+
| Initial code & docs    | Jeff Bass       | `@jeffbass `_               |
+------------------------+-----------------+----------------------------------------------------------+
| Added PUB / SUB option | Maksym Bodnar   | `@bigdaddymax `_         |
+------------------------+-----------------+----------------------------------------------------------+
| HTTP Streaming example | Maksym Bodnar   | `@bigdaddymax `_         |
+------------------------+-----------------+----------------------------------------------------------+
| Fast PUB / SUB example | Philipp Schmidt | `@philipp-schmidt `_ |
+------------------------+-----------------+----------------------------------------------------------+

Helpful Forks of imageZMQ
=========================
Some users have come up with Forks of **imageZMQ** that I think will be helpful
to others, either by using their code or reading their changed code. If
you have developed a fork of **imageZMQ** that demonstrates a concept that
would be helpful to others, please open an issue describing your fork so we
can have a discussion first rather than opening a pull request. Thanks!

+----------------------------+------------+----------------------------------------------------------------------+
| **Helpful Fork**           | **Name**   | **GitHub repository of fork**                                        |
+----------------------------+------------+----------------------------------------------------------------------+
| Add timeouts to image      | Pat Ryan   | `@youngsoul `_ See CHANGES.md |
| sender to fix restarts or  |            |                                                                      |
| non-response of ImageHub   |            |                                                                      |
+----------------------------+------------+----------------------------------------------------------------------+

Acknowledgements and Thank Yous
===============================
- **ZeroMQ** is a great messaging library with great documentation
  at `ZeroMQ.org `_.
- **PyZMQ** serialization examples provided a starting point for **imageZMQ**. See the
  `PyZMQ documentation `_.
- **OpenCV** and its Python bindings provide great scaffolding for computer
  vision projects large or small: `OpenCV.org `_.
- **Picamera2** is a well documented `library `_ for accessing the features and
  settings of the PiCamera modules for various Raspberry Pi single board
  computers. 

Citing this Software
====================
To cite this software in publications, refer to the CITATION.cff file. Or use either of the following: 

APA: 

Bass, J. (2024). imageZMQ: Transporting OpenCV Images (Version 1.2.0) [Computer software]. https://doi.org/10.5281/zenodo.12770292

BibTex:

@software{Bass_imageZMQ_Transporting_OpenCV_2024,
author = {Bass, Jeff},
doi = {10.5281/zenodo.12770292},
month = July,
title = {{imageZMQ: Transporting OpenCV Images}},
url = {https://github.com/jeffbass/imagezmq},
version = {1.2.0},
year = {2024}
}

Owner

  • Name: Jeff Bass
  • Login: jeffbass
  • Kind: user
  • Location: Newbury Park, CA
  • Company: Yin Yang Ranch

Studied econometrics in graduate school, then spent a career writing code in stats, economics, and biotech. Now playing with computer vision on Raspberry Pi's.

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Bass"
  given-names: "Jeff"
  orcid: "https://orcid.org/0009-0008-3287-1093"
title: "imageZMQ: Transporting OpenCV Images"
version: 1.2.0
doi: 10.5281/zenodo.12770292
date-released: 2024-07-17
url: "https://github.com/jeffbass/imagezmq"

GitHub Events

Total
  • Issues event: 2
  • Watch event: 29
  • Issue comment event: 6
  • Fork event: 2
Last Year
  • Issues event: 2
  • Watch event: 29
  • Issue comment event: 6
  • Fork event: 2

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 260
  • Total Committers: 7
  • Avg Commits per committer: 37.143
  • Development Distribution Score (DDS): 0.077
Past Year
  • Commits: 54
  • Committers: 1
  • Avg Commits per committer: 54.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Jeff Bass j****2@g****m 240
bigdaddymax m****b@g****m 8
Indrit Fejza f****t@g****m 5
Philipp Schmidt S****4@g****m 4
retro-node 5****e 1
Yaseen 9****0 1
Tim Sears t****m@t****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 74
  • Total pull requests: 24
  • Average time to close issues: 4 months
  • Average time to close pull requests: 4 days
  • Total issue authors: 68
  • Total pull request authors: 9
  • Average comments per issue: 4.03
  • Average comments per pull request: 1.79
  • Merged pull requests: 22
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 11
  • Average time to close issues: 3 days
  • Average time to close pull requests: 3 minutes
  • Issue authors: 1
  • Pull request authors: 1
  • Average comments per issue: 2.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 11
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • julio16101 (3)
  • alter-sachin (2)
  • panecho (2)
  • ashutoshIITK (2)
  • jcardenaslie (2)
  • tulbureandreit (1)
  • ChesterProgram (1)
  • mamintatarin (1)
  • jogiji (1)
  • projectdrone2 (1)
  • johnhh2 (1)
  • kdziedzic66 (1)
  • timsears (1)
  • kevinlinxc (1)
  • omartin2010 (1)
Pull Request Authors
  • jeffbass (23)
  • bigdaddymax (2)
  • fjolublar (2)
  • StiiCeva (1)
  • ynx0 (1)
  • timsears (1)
  • retro-node (1)
  • philipp-schmidt (1)
  • youngsoul (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 3,653 last-month
  • Total docker downloads: 530
  • Total dependent packages: 3
  • Total dependent repositories: 44
  • Total versions: 3
  • Total maintainers: 1
pypi.org: imagezmq

Transporting OpenCV images via ZMQ

  • Versions: 3
  • Dependent Packages: 3
  • Dependent Repositories: 44
  • Downloads: 3,653 Last month
  • Docker Downloads: 530
Rankings
Stargazers count: 2.0%
Dependent repos count: 2.2%
Docker downloads count: 2.9%
Forks count: 4.0%
Average: 4.4%
Downloads: 5.5%
Dependent packages count: 10.0%
Maintainers (1)
Last synced: 5 months ago