I need to get the Pixels of the render pass to convert them to a numpy array within a python script. From my research there are 3 possible ways to solve this:
- using a viewer node in Compositor
- using a GPU texture
- saving to disk and loading image
I made it work using the first option like this:
pixels = bpy.data.images['Viewer Node'].pixels arr = np.array(pixels[:]).reshape((height,width,4))
However as stated in a lot of other questions and answers (that are a couple of years old) this does not work when blender is in background mode or in my case when using blender as a built python module, since the rendering of viewer nodes was disabled for performance reasons when in background (Python render script different outcome when run in background). I tried fixing the source code according to the answer given in the linked question which solved the problem but now blender doesn't free some memory blocks (probably since the Viewer buffer is not freed in background mode).
Since all the posts asking this question are already a couple of years old and for Blender 2.x versions i wanted to ask if there is a better for solution for retrieving the pixel data in Blender 3 or someone has advice on how to fix the memory leak?