Convert 3 channel BGR image to bytes string in C++ [closed]
I am trying to convert a BGR Mat image to bytes string in C++. So that I can pass it to a python server (along with its spatial dimensions values) where I can reconstruct the image. The code I used is:
//opencvimage is the Mat object (BGR image)
string matAsString(opencvimage.begin<unsigned char>(), opencvimage.end<unsigned char>());
This however extracts only the first channel of the image (I assume it is the Blue channel). How can I get all the 3 channels into the string so that when reconstruct in python:
image = numpy.fromarray(matAsString,dtype=np.uint8).reshape(rows,cols,3)
I get the exact same image?
why do you think, you need a string , to send a (binary) image over the wire ?
Am integrating it with python using pybind11. So it's easier to transfer via byte string
if at all, rather use:
and then, careful, this is NOT unicode (which python might expect, idk.)
maybe it's better, to imencode() it into a png, and send that over the wire
Thanks the
string matAsString(opencvimage.datastart, opencvimage.dataend);
works