In Python, I have this:
retL, imgL = wallie.vidStreamL.read()
wallie.lastL = cv2.cvtColor(imgL, cv2.COLOR_BGR2RGB)
bytes = bytearray(wallie.lastL.tobytes())
return bytes, len(bytes)
So I take an BGR image (OpenCV default, right?), convert it and then return the bytes. It is a embedded Python so then in C++, using the Python.h (3.10):
auto str = PyByteArray_AsString(PyTuple_GetItem(tuple, 0));
auto c = PyLong_AsSize_t(PyTuple_GetItem(tuple, 1));
Then, I need to send this as PoolByteArray to Godot:
PoolByteArray arr;
for (int i = 0; i < c; ++i)
{
arr.append(str[i]);
}
Dictionary snap_out;
snap_out[Variant("len")] = int(c);
snap_out[Variant("arr")] = arr;
return snap_out;
Finally, I try to recreate an image from this in GDScript:
var img = Image.new()
img.create_from_data(1920, 1080, false, Image.FORMAT_RGB8, snap_out["arr"])
self.set_texture(img)
I'm getting correct size gray color rectangle which may mean it's just unrecognized as an image because that's a default color. Which step looks like causing the problem?