I know this issue has been mentioned before but I looked at all similar questions and did not find my exact answer. So here is my problem:

I need to get a full depth map of my render. I mean the distance of all pixels from camera. Answers usually leads to the point that we get a grey level image which far pixels are black and close ones are white, which is not what I'm looking for. Because it does some normalizations and the RGB has some limitations which decrease the accuracy. What I need is to save all Z values directly to a .csv file (or .EXR but I don't know much about it and .csv works for me) that keeps the Z value of all pixels.

Is it simply possible? Or I should a script for it? If an script is needed what is the function to get the Z pass of x,y pixel?



You can obtain depth values by plugin the depths calculated at render time to a "viewer node" in the compositor.

First make sure the rendering uses z (should be set by default):

enter image description here

Setup the viewer node in the compositor:

enter image description here

Render the image (F12).

Now you can have data from Python (principles only below):

img=bpy.data.images['Viewer Node'] # get the image corresponding to the viewer node

img.size # the image size width=img.size[0] height=img.size[1]

img.pixels # raw vector of pixels representing the depths. You'll have to reshape it to obtain a matrix, using numpy or by other means

What's remaining is to write it to a file (which is no more related to Blender).

Hope that helps.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.