Finally I managed like this:
block = qt.QByteArray(message.payload)
out = qt.QDataStream(block, qt.QIODevice.ReadOnly)
out.setVersion(qt.QDataStream.Qt_5_10)
png = out.readBytes()
text = out.readQString()
img_np = cv2.imdecode(np.fromstring(png, np.uint8), cv2.IMREAD_COLOR) # cv2.IMREAD_COLOR in OpenCV 3.1
cv2.imshow("test", img_np)
I am sending as PNG from Qt C++ . through mqtt . ie:
QByteArray blob = file.readAll();
QByteArray ba;
if (img_path.contains("png")){
//QImage to convert PNG in memory
QImage img(img_path);
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
img.save(&buffer, "PNG");
}
Bu I am still not sure this is the best way . Because there is mqt server between and things going unpredictable any time which I experienced.
python code and the Qt C++ code is in the same machine or at least same switch network.
What could be the best way to communicate between them ?