godot-python
godot-python copied to clipboard
set PoolByteArray from Python Bytes object faster
Hello, I'm having a lot of trouble with the speed of data transfer from Python "Bytes" object to Godot PoolByteArray ... I'm trying to get a video feed on a texture in Godot from Opencv ... And whiled Opencv runs fast, I end up at a ridicule 14 fps by doing this:
self.CanWrite = False
self.object = bytes(self.frame.flatten())
with self.ColorArray.raw_access() as arr:
arr[0:(480*640*3)] = self.object
self.CanWrite = True
Which is already faster than a for loop over each elements ... I'm trying to do the process with a jitted numba cfunc ... but I have a lot of trouble identifying what type should I pass to numba ...
Any advice on how I should approach this problem ... For the moment my opencv process and my transfer of the image takes about 0.067 sec. I'd be happy if I can make it take less than 0.033 sec in order to reach at least 30fps.
Best regards,
Do you think that I could get around the problem by compiling a C based GDNative function where I would pass my python bytearray and my godot byte array ?
My guess is you should try to avoid doing buffer copy, so if you could make self.frame.flatten directly work on the self.ColorArray (typically by passing the pointer on the memory area, this is something well supported by numba&friends)
@fuderiki I'm trying to get the same use case running, did you eventually solve the 30fps speed issue? Thanks
Hello there. Same problem here, still can't find good solution.