0

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()
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Hossein
  • 1,152
  • 1
  • 16
  • 32
  • 1
    While RabbitMQ is able to distribute messages with pretty much any payload, it is not designed for large amounts of binary data. You should expect a substantial use of system ressource and performance loss when trying to "stream" video over it. – Klaus D. Jun 12 '19 at 22:09
  • https://stackoverflow.com/questions/46072174/send-images-using-rabbitmq – bumblebee Jun 13 '19 at 06:40

0 Answers0