diff --git a/SDK/Python/blender_script.py b/SDK/Python/blender_script.py index efc381e21ca1f96f59913cbb9df221d17a4c415f..d32e53f1847f5222f3ce4894e5ba5334ffb1b6c3 100644 --- a/SDK/Python/blender_script.py +++ b/SDK/Python/blender_script.py @@ -140,34 +140,18 @@ def render(): rl = tree.nodes.new('CompositorNodeRLayers') v = tree.nodes.new('CompositorNodeViewer') - v.use_alpha = False - - #setup the depthmap calculation using blender's mist function: - #bpy.context.scene.render.layers['RenderLayer'].use_pass_mist = True - #bpy.context.scene.view_layers["View Layer"].use_pass_mist = True - #the depthmap can be calculated as the distance between objects and camera ('LINEAR'), or square/inverse square of the distance ('QUADRATIC'/'INVERSEQUADRATIC'): - bpy.context.scene.world.mist_settings.falloff = 'LINEAR' - #minimum depth: - bpy.context.scene.world.mist_settings.intensity = 0.1 - #maximum depth (can be changed depending on the scene geometry to normalize the depth map whatever the camera orientation and position is): - bpy.context.scene.world.mist_settings.depth = 8.0 - - links.new(rl.outputs['Depth'],v.inputs['Image']) - bpy.ops.render.render() - pixels = bpy.data.images['Viewer Node'] - depthim = (np.array(pixels.pixels[:]).reshape((pixels.size[1], pixels.size[0], pixels.channels))[:,:,0]).astype(np.float32) - # set invalid depth values to 0.0 - depthim[depthim >= _d_max] = 0.0 - - print(np.amax(depthim)) + v.use_alpha = True links.new(rl.outputs['Image'], v.inputs['Image']) # depth cannot be accessed in python; hack uses alpha to store z-values - #links.new(rl.outputs['Depth'], v.inputs['Alpha']) + links.new(rl.outputs['Depth'], v.inputs['Alpha']) bpy.ops.render.render() - pixels2 = bpy.data.images['Viewer Node'] - im = np.array(pixels2.pixels[:]).reshape((pixels2.size[1], pixels2.size[0], pixels2.channels)) + pixels = bpy.data.images['Viewer Node'] + im = np.array(pixels.pixels[:]).reshape((pixels.size[1], pixels.size[0], pixels.channels)) + depthim = (np.array(pixels.pixels[:]).reshape((pixels.size[1], pixels.size[0], pixels.channels))[:,:,3]).astype(np.float32) + # set invalid depth values to 0.0 + depthim[depthim >= _d_max] = 0.0 return (im[:,:,0:3]*255.0).astype(np.uint8), depthim @@ -181,7 +165,7 @@ def render_stereo(camera, baseline=0.15): imR, depthR = render() - camera_location = location_old + camera.location = location_old return StereoImage(np.array(K), pose, baseline, imL, depthL, imR, depthR) @@ -217,8 +201,8 @@ scale = bpy.context.scene.render.resolution_percentage / 100 resolution_x_in_px = scale * bpy.context.scene.render.resolution_x resolution_y_in_px = scale * bpy.context.scene.render.resolution_y -err = ftlIntrinsicsWriteLeft(c_void_p(stream), c_int(0), c_int(int(resolution_x_in_px)), c_int(int(resolution_y_in_px)), c_float(300.0), c_float(-resolution_x_in_px/2), c_float(-resolution_y_in_px/2), c_float(0.1), c_float(0.1), c_float(8.0)) -err = ftlIntrinsicsWriteRight(c_void_p(stream), c_int(0), c_int(int(resolution_x_in_px)), c_int(int(resolution_y_in_px)), c_float(300.0), c_float(-resolution_x_in_px/2), c_float(-resolution_y_in_px/2), c_float(0.1), c_float(0.1), c_float(8.0)) +err = ftlIntrinsicsWriteLeft(c_void_p(stream), c_int(0), c_int(int(resolution_x_in_px)), c_int(int(resolution_y_in_px)), c_float(300.0), c_float(-resolution_x_in_px/2), c_float(-resolution_y_in_px/2), c_float(0.1), c_float(0.1), c_float(16.0)) +err = ftlIntrinsicsWriteRight(c_void_p(stream), c_int(0), c_int(int(resolution_x_in_px)), c_int(int(resolution_y_in_px)), c_float(300.0), c_float(-resolution_x_in_px/2), c_float(-resolution_y_in_px/2), c_float(0.1), c_float(0.1), c_float(16.0)) print(err) err = ftlImageWrite(stream, 0, 0, 3, 0, image.imL.ctypes.data_as(c_void_p)) print(err)