This tool is intended as an example for publishing decoded image frames in the (BGR HWC format) to the Nimble
source data stream.
This tool also demonstrates the feature in Nimble to ingest from a zmq source, configurable through the Nimble configuration json.
You can find it under
tools/zmq/publisher. This example also uses
tools/zmq/subscriber to listen to the Nimble output,
you can find the subscriber example here.
To run the example:
user@host:~$ docker-compose up --build
The publisher binds a port and awaits an incoming connection from the nimble zmq source, alternatively the publisher can initiate a connection to a proxy.
ctx = zmq.Context()
pub = ctx.socket(zmq.PUB)
The send buffer queue water marks are specifically set to sync with slow subscribers without causing queue overflows or mem leaks. The zmq publisher socket is setup to receive decoded frames in the HWC (rows x cols x channels) format, with the channels being in the BGR color order. This sample demonstrates a simple opencv videocapture from a video file source
cap = cv2.VideoCapture("videos/demo-tracking-28s.mp4")
ret, image = cap.read()
Note that a compact and fast serialization format is used to transfer image bytes over the zmq.
The Nimble zmq
source expects to receive the following multipart message:
- the image byte array in the HWC (rows x cols x channels) format, with the channels being in the BGR color order, serialized through msgpack
- the datatype of the mat/numpy representing the image, converted to str and utf-8 encoded
- the # of rows of the image mat/numpy, converted to str and utf-8 encoded
- the # of cols of the image mat/numpy, converted to str and utf-8 encoded
This sample publisher restarts on EOS and tries to publish image packets to Nimble indefinitely until termination.
There is an additional example under
tools/zmq/proxy which allows for a publisher to initiate a connection to proxy, instead of listening for incoming nimble requests.
This is useful when the publisher's IP address isn't fixed and needs to be the initiator.
The proxy microservice is given as a sample but can be integrated directly into nimble