将图像发送到RabbitMQ

时间:2019-06-12 21:58:02

标签: python opencv rabbitmq

我需要通过RabbitMQ发送/接收OpenCV图像,显然我遇到了序列化问题。我收到的错误是:

  

ValueError:具有多个元素的数组的真值不明确。使用a.any()或a.all()

RabbitMQ是否允许以这种形式发送图像?

在客户端,我有:

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)

在接收方,我有:

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()

0 个答案:

没有答案