Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open3d.visualization.draw() function run on window system with python call bug: #7058

Open
3 tasks done
Zhouwudexiazhou opened this issue Nov 17, 2024 · 0 comments
Open
3 tasks done
Labels
bug Not a build issue, this is likely a bug.

Comments

@Zhouwudexiazhou
Copy link

Checklist

Describe the issue

My script needs to render the image using the O3DVisualizer class in open3d, and this functionality is encapsulated in the o3d.Visual.draw function, which is used in my script. Since I need to call this function several times to render the picture, I call o3d.visualization.draw a number of times, but each time at the 940th call, the program exits with the exit code of -1073741819 (0xC0000005), the process has ended. At first I thought it was because of insufficient memory, so I modified the o3d.visualization.draw in open3d, manually released the created renderer and window and point cloud files, but it still didn't work, can anyone tell me why?

Steps to reproduce the bug

import os
import numpy as np
import open3d as o3d
import gc

def render_photo(pcd, center, eye_positions, save_path):
    for i, eye in enumerate(eye_positions):
        out_path = os.path.join(save_path, fr"photo_{i}.png")
        try:
            o3d.visualization.draw(
                geometry=[{
                    "name": "pcd",
                    "geometry": pcd
                }],
                title="3D Vis",
                width=1280,
                height=720,
                lookat=np.array(center, dtype=np.float32),
                eye=np.array(eye, dtype=np.float32),
                up=np.array([0.0, 1.0, 0.0], dtype=np.float32),
                field_of_view=60.0,
                bg_color=(255.0, 255.0, 255.0, 1.0),
                show_skybox=False,
                point_size=2,
                run_one=True,
                save_image=out_path
            )
            gc.collect()
        except Exception as e:
            print(e)
path = r"D:\VVBTV\datasets\video_raw_patch_datasets\longdress\frame_0_patch_0.ply"
save = r"D:\VVBTV\datasets\ssim_photo\raw_photo"
pcd = o3d.io.read_point_cloud(path)
center = np.array([202, 259.5, 96])
position = np.array([[-798. ,  259.5,   96. ], [1202. ,  259.5,   96. ], [ 202. , -740.5,   96. ], [ 202. , 1259.5,   96. ], [ 202. ,  259.5, -904. ], [ 202. ,  259.5, 1096. ]])
time_idx = 1
while True:
    render_photo(pcd, center, position, save)
    print(f"this is the {time_idx} time to render a photo")
    time_idx += 1
the draw function modified code is :from . import gui
from . import O3DVisualizer
import gc


def draw(geometry=None,
         title="Open3D",
         width=1024,
         height=768,
         actions=None,
         lookat=None,
         eye=None,
         up=None,
         field_of_view=60.0,
         intrinsic_matrix=None,
         extrinsic_matrix=None,
         bg_color=(1.0, 1.0, 1.0, 1.0),
         bg_image=None,
         ibl=None,
         ibl_intensity=None,
         show_skybox=None,
         show_ui=None,
         raw_mode=False,
         point_size=None,
         line_width=None,
         animation_time_step=1.0,
         animation_duration=None,
         rpc_interface=False,
         on_init=None,
         on_animation_frame=None,
         on_animation_tick=None,
         non_blocking_and_return_uid=False,
         run_one = False,
         save_image=None):
    render_app = gui.Application.instance
    render_app.initialize()
    # gui.Application.instance.initialize()
    w = O3DVisualizer(title, width, height)
    w.set_background(bg_color, bg_image)

    if actions is not None:
        for a in actions:
            w.add_action(a[0], a[1])

    if point_size is not None:
        w.point_size = point_size

    if line_width is not None:
        w.line_width = line_width

    def add(g, n):
        if isinstance(g, dict):
            w.add_geometry(g)
        else:
            w.add_geometry("Object " + str(n), g)

    n = 1
    if isinstance(geometry, list):
        for g in geometry:
            add(g, n)
            n += 1
    elif geometry is not None:
        add(geometry, n)

    w.reset_camera_to_default()  # make sure far/near get setup nicely
    if lookat is not None and eye is not None and up is not None:
        w.setup_camera(field_of_view, lookat, eye, up)
    elif intrinsic_matrix is not None and extrinsic_matrix is not None:
        w.setup_camera(intrinsic_matrix, extrinsic_matrix, width, height)

    w.animation_time_step = animation_time_step
    if animation_duration is not None:
        w.animation_duration = animation_duration

    if show_ui is not None:
        w.show_settings = show_ui

    if ibl is not None:
        w.set_ibl(ibl)

    if ibl_intensity is not None:
        w.set_ibl_intensity(ibl_intensity)

    if show_skybox is not None:
        w.show_skybox(show_skybox)

    if rpc_interface:
        w.start_rpc_interface(address="tcp://127.0.0.1:51454", timeout=10000)

        def stop_rpc():
            w.stop_rpc_interface()
            return True

        w.set_on_close(stop_rpc)

    if raw_mode:
        w.enable_raw_mode(True)

    if on_init is not None:
        on_init(w)
    if on_animation_frame is not None:
        w.set_on_animation_frame(on_animation_frame)
    if on_animation_tick is not None:
        w.set_on_animation_tick(on_animation_tick)

    render_app.add_window(w)

    if save_image is not None:
        w.export_current_image(save_image)

    if not run_one:
        if non_blocking_and_return_uid:
            return w.uid
        else:
            render_app.run()
    else:
        render_app.run_one_tick()
        del geometry
        w.remove_geometry("Object " + str(1))
        w.close()
        render_app.quit()
    w.clear_3d_labels()
    del w
    del render_app

Error message

The last error on the output end is not reported, but the process has ended and the exit code is -1073741819 (0xC0000005)

Expected behavior

I hope you can tell me what caused this, and it would be better if you could tell me how to solve it

Open3D, Python and System information

- Operating system: Windows 10 64-bit
- Python version: Python 3.9.18
- Open3D version: 0.18.0
- System architecture: x86
- Is this a remote workstation?: no
- How did you install Open3D?: pip

Additional information

No response

@Zhouwudexiazhou Zhouwudexiazhou added the bug Not a build issue, this is likely a bug. label Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Not a build issue, this is likely a bug.
Projects
None yet
Development

No branches or pull requests

1 participant