Extracting depth data

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

cmathewc
Posts: 2
Joined: Sat Jul 14, 2012 12:52 am

Extracting depth data

Postby cmathewc » Sat Jul 14, 2012 1:48 am

Hello,

I am part of a research group doing some work in graphics. I would like to export the depth information as an image/text file using a python script. I have been googling this for quite a few days and I still have not got anything that actually works.

Waiting for your response,

Thank you.

Mathew

kmatzen
Posts: 2
Joined: Sat Jul 07, 2012 12:16 am

Postby kmatzen » Sun Jul 22, 2012 9:26 pm

Render your scene to OpenEXR format and enable the ZBuf option. I think I've had trouble in the past with some programs reading this multilayer EXR format. For example, while Photoshop supports the EXR files that Blender generates with ZBuf disabled, I had to install a plugin to open the multilayer version.

I usually split the EXR files outside of Blender. For this I use the OpenEXR package. http://pypi.python.org/pypi/OpenEXR/1.2.0 Here's a snippet to get you started. It uses numpy arrays to store the data. Originally adapted from http://opencv.willowgarage.com/document ... nd-openexr.

Code: Select all

import OpenEXR
import Imath
import numpy

# your filename here
exrimage = OpenEXR.InputFile(filename)

dw = exrimage.header()['dataWindow']
(width, height) = (dw.max.x - dw.min.x + 1, dw.max.y - dw.min.y + 1)

def fromstr(s):
  mat = numpy.fromstring(s, dtype=numpy.float16)
  mat = mat.reshape (height,width)
  return mat

pt = Imath.PixelType(Imath.PixelType.HALF)
(r, g, b, a, z) = [fromstr(s) for s in exrimage.channels('RGBAZ', pt)]

cmathewc
Posts: 2
Joined: Sat Jul 14, 2012 12:52 am

Thank you

Postby cmathewc » Thu Jul 26, 2012 9:26 pm

Hi,

I found another method to do the same. Slightly round about but works just the same.

Thanks anyways for your reply.

Mathew


Return to “Python”

Who is online

Users browsing this forum: No registered users and 0 guests