I'm new to working with both Blender and bpy, and I'm trying to render directly into Python. Best case, I could render directly from bpy 2.82 into a byte stream or numpy matrix.
I've been trying to follow the instructions here https://ammous88.wordpress.com/2015/01/16/blender-access-render-results-pixels-directly-from-python-2/, using bpy.data.images["Viewer Node"].pixels, but it's returning something of size 262,144 which doesn't make any sense. The link was written for Blender version 2.7, so I assume the API changed somehow between the two.
I have bpy.context.scene.render.resolution_x and bpy.context.scene.render.resolution_y set to 320 and 480 respectively, so I would assume there would be 320x480x4=614,400 total pixels.
Is there any way to do what I'm trying to do in Blender version 2.82?
Here's the code from the link above:
import bpy
import numpy as np
# switch on nodes
bpy.context.scene.use_nodes = True
tree = bpy.context.scene.node_tree
links = tree.links
# clear default nodes
for n in tree.nodes:
tree.nodes.remove(n)
# create input render layer node
rl = tree.nodes.new('CompositorNodeRLayers')
rl.location = 185,285
# create output node
v = tree.nodes.new('CompositorNodeViewer')
v.location = 750,210
v.use_alpha = False
# Links
links.new(rl.outputs[0], v.inputs[0]) # link Image output to Viewer input
# render
bpy.ops.render.render()
# get viewer pixels
pixels = bpy.data.images['Viewer Node'].pixels
print(len(pixels)) # size is always width * height * 4 (rgba)
# copy buffer to numpy array for faster manipulation
arr = np.array(pixels[:])
```