python - 将图像发送到 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()
解决方案
推荐阅读
- python - TypeError: __init__() 得到了一个意外的关键字参数 'i'
- pdf - 在 pdf dart 中使用画布绘制线条
- angular - 角度 CORS 预检请求导致 400 错误请求,但邮递员请求工作正常
- javascript - usePreviousDistinct 有 useEffect 和没有 useEffect 之间的区别
- saxon - xsl:accumulator 中的副作用
- selenium - Robotframework如何做一个TextField值应该是IN a Loop?
- docker - Windows 容器的 dockerfile 中的问题设置 [Net.ServicePointManager]::SecurityProtocol
- mysql - MySQL 错误 1215 无法添加外键约束
- python - 如何在pytube3中使用进度条
- java - 日志文件中没有打印日志,但它正在打印在 cosole [log4j]