0
我需要與RabbitMQ的,我發現的唯一途徑發送圖像是:如何將磁盤上的簡單圖像轉換爲OpenCV mat文件?
f = open("asd.jpg","rb")
img = f.read()
f.close()
比我能發送img
。
我想處理髮送的圖像,我收到它,所以我如何將它轉換爲OpenCV mat文件?
這裏是我收到的文件:
def callback(ch, method, properties, body):
print "Recieved"
cv2.imshow('Message', body)
cv2.waitKey(0)
Send.py:
import pika
import cv2
img = cv2.imread('asd.jpg')
#Establish connection
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.exchange_declare(exchange='image_exch', type='fanout')
channel.basic_publish(exchange='image_exch', routing_key='', body=img)
print "[*] Sent"
connection.close()
Receive.py:
import pika
import cv2
#Establish connection
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.exchange_declare(exchange='image_exch', type='fanout')
result = channel.queue_declare(exclusive=True)
queue_name = result.method.queue
channel.queue_bind(exchange='image_exch', queue=queue_name)
def callback(ch, method, properties, body):
print "Recieved"
cv2.imshow('Message', body)
cv2.waitKey(0)
channel.basic_consume(callback, queue=queue_name, no_ack=True)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
爲什麼你不只是使用opencv讀取圖像?它將被讀作一個numpy數組。 –
因此,首先我必須保存它,並用openCV再次讀取它?或者我不明白。 – Gabe
檢查我的答案。 –