使用 protobuf 序列化图像流
Serializing image stream using protobuf
我在 Ubuntu 中有两个程序:一个 C++ 程序(TORCS 游戏)和一个 python 程序。 C++ 程序总是生成图像。我想把这些实时图像转成python(可能是numpy.ndarray格式)。所以我觉得或许使用Google protobuf将图片序列化为字符串,通过ZMQ发送给python客户端是一个可行的方法。
问题:.proto
文件中的图像(指针)适合哪种值类型?换句话说,我应该使用哪种值类型来替换下面示例中的 string
类型?
message my_image{
repeated string image = 1
}
这是我将图像写入内存的方式(uint8_t* image_data):
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)image_data);
最后,也许有更好的方法将图像(在内存中)传输到 python 客户端?
如有任何建议,我们将不胜感激。
如果我必须这样做,我会使用以下之一:
message image {
int width = 1;
int height = 2;
bytes image_data = 3;
}
message image {
int width = 1;
int height = 2;
bytes red_data = 3;
bytes green_data = 4;
bytes blue_data = 5;
}
或者可能使用中间 ScanRow
消息,由交错的 R、G、B 字节或分开的 R、G、B 字节组成。第一个版本的生成和显示速度可能最快。
根据此博客 post :https://medium.com/@brynmathias/kafka-and-google-protobuf-a-match-made-in-python-a1bc3381da1a
您可以使用以下架构:
syntax = 'proto3';
package protobuf.data;
import "protobuf/common/messageData.proto";
message Image {
bytes image_data = 1;
int32 height = 2;
int32 width = 3;
int64 frame = 4;
protobuf.common.messageData _message_data = 5;
}
我在 Ubuntu 中有两个程序:一个 C++ 程序(TORCS 游戏)和一个 python 程序。 C++ 程序总是生成图像。我想把这些实时图像转成python(可能是numpy.ndarray格式)。所以我觉得或许使用Google protobuf将图片序列化为字符串,通过ZMQ发送给python客户端是一个可行的方法。
问题:.proto
文件中的图像(指针)适合哪种值类型?换句话说,我应该使用哪种值类型来替换下面示例中的 string
类型?
message my_image{
repeated string image = 1
}
这是我将图像写入内存的方式(uint8_t* image_data):
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)image_data);
最后,也许有更好的方法将图像(在内存中)传输到 python 客户端?
如有任何建议,我们将不胜感激。
如果我必须这样做,我会使用以下之一:
message image {
int width = 1;
int height = 2;
bytes image_data = 3;
}
message image {
int width = 1;
int height = 2;
bytes red_data = 3;
bytes green_data = 4;
bytes blue_data = 5;
}
或者可能使用中间 ScanRow
消息,由交错的 R、G、B 字节或分开的 R、G、B 字节组成。第一个版本的生成和显示速度可能最快。
根据此博客 post :https://medium.com/@brynmathias/kafka-and-google-protobuf-a-match-made-in-python-a1bc3381da1a
您可以使用以下架构:
syntax = 'proto3';
package protobuf.data;
import "protobuf/common/messageData.proto";
message Image {
bytes image_data = 1;
int32 height = 2;
int32 width = 3;
int64 frame = 4;
protobuf.common.messageData _message_data = 5;
}