I need to send/receive OpenCV images through RabbitMQ, apparently I'm running into problems with serialization. The error that I'm getting is:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Does RabbitMQ allow sending images in this form?
on the client side I have:
from imutils.video import VideoStream
import argparse
import socket
import time
import pika
import numpy as npfrom imutils.video import VideoStream
import argparse
import socket
import time
import pika
import numpy as np
import sys
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.exchange_declare(exchange='logs', exchange_type='fanout')
vs = VideoStream(src=0).start()
time.sleep(2.0)
while True:
frame = vs.ref
channel.basic_publish(exchange='vids', routing_key='', body=frame)
and on the receive side I have:
from imutils import build_montages
from datetime import datetime
import numpy as np
import argparse
import imutils
import cv2
import pika
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.exchange_declare(exchange='vids', exchange_type='fanout')
result = channel.queue_declare(queue='', exclusive=True)
queue_name = result.method.queue
channel.queue_bind(exchange='vids', queue=queue_name)
def callback(ch, method, properties, body):
thresh = 127
body = cv2.threshold(body, thresh, 255, cv2.THRESH_BINARY)[1]
cv2.imshow("Home pet location monitor ({})".format(1),body)
channel.basic_consume(
queue=queue_name, on_message_callback=callback, auto_ack=True)
channel.start_consuming()