首页 > 解决方案 > 将图像发送到 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()

标签: pythonopencvrabbitmq

解决方案


推荐阅读