I have two programs in Ubuntu: a C++ program (TORCS game) and a python program. The C++ program always generates images. I want to transfer these real-time images into python(maybe the numpy.ndarray format). So I think that maybe using Google protobuf to serialize the image to string and send string to python client by ZMQ is a feasible method.
Question: which value type is suitable for the image(a pointer) in .proto
file? In another words, which value type I should use to replace string
type in the below example?
message my_image{
repeated string image = 1
}
This is the way I write image to memory (uint8_t* image_data):
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)image_data);
At last, maybe there is a better way to transfer image (in the memory) to a python client?
Any suggestions are appreciated.
Protocol buffers messages always use little-endian encoding.
Protobuf is create for serialize purpose so I recommend you no need to serialize it again to a Serializable or Parcelable object. Instead of, serialize it to byte array and put byte array to to bundle.
In one – protobufjs was faster, and in the second — JSON was faster. Looking at the schemas, the immediate suspect was the number of strings. We ran the benchmark with this payload (10,000 strings, of length 10 each).
You can certainly send even a binary payload with an HTTP request, or in an HTTP response. Just write the bytes of the protocol buffer directly into the request/response, and make sure to set the content type to "application/octet-stream". The client, and server, should be able to take care of the rest easily.
If I had to do this, I would use one of:
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;
}
Or possibly use an intermediate ScanRow
message, composed either of interleaved R, G, B bytes or separated R, G, B bytes. The first version is likely going to be fastest to generate and display.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With