Previous Thread  Next Thread

chat icon Extracting depth data

cmathewc

Posted: Sat Jul 14, 2012 12:48 am
Joined: 13 Jul 2012
Posts: 2
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
Reply with quote


kmatzen

Posted: Sun Jul 22, 2012 8:26 pm
Joined: 06 Jul 2012
Posts: 2
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/documentation/python/cookbook.html#opencv-and-openexr.

Code:

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)]
Reply with quote


cmathewc

Posted: Thu Jul 26, 2012 8:26 pm
Joined: 13 Jul 2012
Posts: 2
Hi,

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

Thanks anyways for your reply.

Mathew
Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group