WorldViz User Forum Extracting high precision depth map from scene
 Register FAQ Search Today's Posts Mark Forums Read

#1
09-03-2019, 04:15 AM
 josephredfern Member Join Date: Sep 2019 Posts: 8
Extracting high precision depth map from scene

Hello,

I'm new to using Vizard, and attempting to extract high-precision depth data from a scene.

At the moment, to do this, I am using:

Code:
float_buff = depth.saveToBuffer('<raw>', dataType=viz.GL_FLOAT)

size = depth.getSize()
w = size[0]
h = size[1]

d_float = np.fromstring(float_buff, np.float32, w*h)

np.save('depth.npy', d_float.reshape((w, h)))

This allows me to save the values of the depth render texture to a numpy array... but I have a few questions:
• What units is this depth texture in? For the piazza scene, all/most values seem to be around 0.9. Is there a way of converting this to meters?
• The dimension of the resulting texture is always 512x512. How is this controlled?
• Is this the correct way to extract the depth? Is there a way of using depth.save() to store an uncompressed numpy array (rather than png/jpg etc?)

Any guidance would be appreciated.

Thanks,
Joe
#2
09-05-2019, 04:24 PM
 Jeff WorldViz Team Member Join Date: Aug 2008 Posts: 2,465
The depth buffer on GPUs is non-linear, in order to provide greater precision to nearby objects.

You can convert a raw depth buffer value to linear and world units using the following code:

Code:
z = <raw depth buffer value>
znear = viz.MainWindow.getNearClip()
zfar = viz.MainWindow.getFarClip()

# Compute normalized linear depth value (0-1 range)
linear = (2 * znear) / (zfar + znear - z * (zfar - znear))

# Compute world depth value (distance from view plane)
world = (2.0 * znear * zfar) / (zfar + znear - (2.0 * z - 1.0) * (zfar - znear))
#3
10-28-2019, 04:53 AM
 josephredfern Member Join Date: Sep 2019 Posts: 8
Hi Jeff,

I forgot to reply to this at the time -- but thank you for your answer, it solved the issue for me.

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements Vizard Precision Position Tracker (PPT) Plug-in development