I want to filter out image data as per the text message attached to it.
Hub Code
import imagezmq
import cv2
hub = imagezmq.ImageHub()
print('Listening')
while True:
rpi_name, image = hub.recv_jpg()
print('Received from ' + rpi_name)
hub.send_reply(b'OK')
Server 1
import imagezmq
import cv2
import simplejpeg
hub = imagezmq.ImageSender()
feed = cv2.VideoCapture(url)
while True:
ret, frame = feed.read()
image = simplejpeg.encode_jpeg(frame, quality=60, colorspace='BGR')
hub.send_jpg('1',image)
Server 2
import imagezmq
import cv2
import simplejpeg
hub = imagezmq.ImageSender()
feed = cv2.VideoCapture(url)
while True:
ret, frame = feed.read()
image = simplejpeg.encode_jpeg(frame, quality=60, colorspace='BGR')
hub.send_jpg('2',image)
In the hub I receive data form both the servers simultaneously. What i want is to filter the data out. Like i just want to receive data which have message(this is used to differentiate servers) 1 only.
Or what would be the fasted way to get data from a server if the hub is receiving data from many servers.
For each (text, image) pair received, the text message contained in rpi_name
contains the '1' or '2' depending on the sending server. To filter images by sending server, you need to
use the text to differentiate what action is done based on the text portion of each message.
Here is one example of how to do that. I have added an example function
do_something()
that uses an if statement to take different actions depending
on the source of the image.
Hub Code (with added function to take different actions based on sending server)
# Here is example Hub code showing how to Filter or take other
# action based on the source of rpi_name, image
#
import imagezmq
import cv2
def do_something(rpi_name, image):
# parameter rpi_name contains the "text message" which differs by server
# parameter image contains the image that arrived from that server
if rpi_name == '1':
pass # or do something like save the image or process it somehow
elif rpi_name == '2':
pass # or do something like save the image or process it somehow
else:
pass # what do you want to do if server is not one of the 2 above?
hub = imagezmq.ImageHub()
print('Listening')
while True:
rpi_name, image = hub.recv_jpg()
print('Received from ' + rpi_name)
do_something(rpi_name, image)
hub.send_reply(b'OK')
FYI, I am the author of imageZMQ.