[英]Send and Consume multiple images simultaneously using Kafka-Python
I want to send two or more images simultaneously from Kafka Producer.我想同时从 Kafka Producer 发送两个或更多图像。 Is it possibile?
有可能吗?
After created a KafkaProducer object kafka_producer
and after got frames from two webcam and converted them into bytes using cv2.imencode
and tobytes()
, I've tried this:在创建了一个 KafkaProducer 对象
kafka_producer
并从两个网络摄像头获取帧并使用cv2.imencode
和tobytes()
将它们转换为字节后,我试过这个:
buffer_frame1 = cv2.imencode('jpg', frame1)
buffer_frame2 = cv2.imencode('jpg', frame2)
kafka_producer.send(topic, buffer_frame1.tobytes())
kafka_producer.send(topic, buffer_frame2.tobytes())
I haven't yet implement a KafkaConsumer, but I want to know if this work, and if it don't why and how can I send multiple images simultaneously.我还没有实现 KafkaConsumer,但我想知道这是否有效,如果无效,为什么以及如何同时发送多个图像。
Thanks!谢谢!
You can encode both bytes objects into another object and then use a serialization library such as pickle (if you must stay within python) to send a single object over the wire.您可以将两个字节对象编码为另一个对象,然后使用诸如 pickle 之类的序列化库(如果您必须留在 python 中)通过网络发送单个对象。
If you must support other types of languages, JSON is perfectly capable of storing bytes如果您必须支持其他类型的语言,JSON 完全能够存储字节
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.