Skip to content

Cannot disable renderer.render_to_image() console output when using OffscreenRenderer #7328

@Stretox

Description

@Stretox

Checklist

Describe the issue

I try to render a scene using o3d.visualization.rendering.OffscreenRenderer

But whenever I call renderer.render_to_image() I get this output

[Open3D INFO] EGL headless mode enabled.
FEngine (64 bits) created at 0x2fa3d850 (threading is enabled)
EGL(1.5)
OpenGL(4.6)

I tried to set:

o3d.utility.set_verbosity_level(o3d.utility.VerbosityLevel.Error)

Which disabled the [Open3D INFO] EGL headless mode enabled. line

I even tried setting

sys.stdout = open(os.devnull, 'w')
sys.stderr = open(os.devnull, 'w')

and tried to use

output = open(os.devnull, 'w')

with redirect_stdout(output), redirect_stderr(output):
    renderer.render_to_image()

Which both still lead to the same output

Steps to reproduce the bug

import open3d as o3d
import numpy as np

def render_offscreen(geo:o3d.geometry, output_path:str):

    renderer = o3d.visualization.rendering.OffscreenRenderer(512, 512)
    renderer.scene.set_background([1.0, 1.0, 1.0, 1.0])
    material = o3d.visualization.rendering.MaterialRecord()

    renderer.scene.add_geometry("bunny", geo, material)

    bounds = geometry.get_axis_aligned_bounding_box()
    center = bounds.get_center()
    extent = bounds.get_extent()
    max_extent = np.max(extent)

    cam_distance = max_extent * 1.2
    eye = center + np.array([0.0, 0.0, cam_distance])
    up = np.array([0.0, 1.0, 0.0])
    vertical_fov = 60.0

    renderer.scene.camera.look_at(center, eye, up)
    renderer.scene.camera.set_projection(
        vertical_fov,
        width / height,
        0.1,
        1000.0,
        o3d.visualization.rendering.Camera.FovType.Vertical
    )

    img = renderer.render_to_image()
    o3d.io.write_image(output_path, img)

Error message

This will generate an output similar to this:

[Open3D INFO] EGL headless mode enabled.
FEngine (64 bits) created at 0x2fa3d850 (threading is enabled)
EGL(1.5)
OpenGL(4.6)

Expected behavior

Only the
[Open3D INFO] EGL headless mode enabled.
Line should appear,

If I set the verbosity to Error there should not be any output in the console

Open3D, Python and System information

- Operating system: Fedora 42/ Ubuntu 22.04
- Python version: Python 3.11.0
- Open3D version: 0.19.0
- System architecture: x86
- Is this a remote workstation?: no
- How did you install Open3D?: pip
- Compiler version (if built from source): ❌

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugNot a build issue, this is likely a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions