godot-python icon indicating copy to clipboard operation
godot-python copied to clipboard

set PoolByteArray from Python Bytes object faster

Open fuderiki opened this issue 6 years ago • 4 comments
trafficstars

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,

fuderiki avatar Jun 06 '19 14:06 fuderiki

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 ?

fuderiki avatar Jun 09 '19 06:06 fuderiki

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)

touilleMan avatar Jun 16 '19 14:06 touilleMan

@fuderiki I'm trying to get the same use case running, did you eventually solve the 30fps speed issue? Thanks

whogben avatar Jun 28 '20 21:06 whogben

Hello there. Same problem here, still can't find good solution.

kzerot avatar May 04 '21 19:05 kzerot