我在 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 字节组成。第一个版本的生成和显示速度可能最快。
关于python - 使用 protobuf 序列化图像流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39244589/