To be able to send an image via HTTP, you also need to encode its width, height and type. You need to serialize Mat into a stream and encode this stream using libb64. On the other hand, you need to decode this stream and deserialize the image to get it.
I implemented a small test program that does this serialization and deserialization using std::stringstream as a buffer. I chose it because it extends both std::istream and std::ostream , which libb64 uses.
The serialize function serialize cv::Mat to std::stringstream . In it I write the width, height, type, size of the buffer and the buffer itself.
The deserialize function does the opposite. It reads the width, height, type, buffer size and buffer. This is not as efficient as it could be, because it needs to allocate a temporary buffer to read data from the string stream. In addition, it must clone the image so that it does not rely on a temporary buffer, and it will process its own memory allocation. I am sure that with some mastering this can be done more efficiently.
The main function loads the image, serializes it, encodes it with libb64, then decodes, deserializes and displays it in the window. This should mimic what you are trying to do.
source share