简体   繁体   English

使用 Kafka-Python 同时发送和使用多个图像

[英]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.imencodetobytes()将它们转换为字节后,我试过这个:

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.

相关问题 Kafka-python如何使用json消息 - Kafka-python How to consume json message 无法使用Kafka-Python的反序列化器从Kafka消耗JSON消息 - Can't Consume JSON Messages From Kafka Using Kafka-Python's Deserializer 在kafka-python中使用Debezium时无法使用来自kafka的消息 - Cannot Consume Messages from kafka when using Debezium in kafka-python 由于 KafkaTimeoutError,无法使用 kafka-python 从 django 应用程序向 kafka 发送消息 - Unable to send messages to kafka from django application using kafka-python due to KafkaTimeoutError 使用 Kafka-python 处理生产者和消费者 - Handling a producer and consumer using Kafka-python 使用 kafka-python 检索主题中的消息 - retrieve messages in a topic using kafka-python Kafka-python Producer执行Send,但Kafka没有数据到达 - Kafka-python Producer performs Send, but no data arrives in Kafka 如何使用 kafka-python 订阅多个 kafka 通配符模式的列表? - How to subscribe to a list of multiple kafka wildcard patterns using kafka-python? kafka-python KafkaConsumer 多分区提交偏移 - kafka-python KafkaConsumer multiple partition commit offset kafka-python:通过运行并发进程/脚本同时产生和消费来自同一主题的消息 - kafka-python: produce and consume messages from same topic at the same time by running concurrent process/scripts
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM