Open3d: 非ブロッキング描画ループ内でdraw_geometries()を呼び出すと、非ブロッキング描画が中断されます

作成日 2018年10月04日  ·  4コメント  ·  ソース: intel-isl/Open3D

non_blocking_visualisation.pyの例を考えてみましょう。
電話すれば

draw_geometries([source_raw]) 

その後いつでも

    vis = Visualizer()
    vis.create_window()

次に、draw_geometriesを終了した後、visを使用しようとすると、次のエラーが出力されます。

GLFWエラー:GLFWライブラリが初期化されていません

その時点以降、visウィンドウには何も表示されません。

このシナリオでは、私が作成しているアプリで、点群をブロックしない方法で表示しています。 しかし、デバッグしているときに、ipythonインタープリターからdraw_geometries()を呼び出して、中間結果を表示することがよくあります。 問題は、現時点では、これを行うと、ノンブロッキングビジュアライゼーションが機能しなくなるため、アプリを続行できないことです。 ノンブロッキングビジュアライゼーションを再度表示するには、アプリを再起動する必要があります。

これを回避するためにできることはありますか?

possible bug

最も参考になるコメント

次のようにdel vis追加します。

vis.destroy_window()
del vis

全てのコメント4件

こんにちは@martinakos。 draw_geometriesは高レベルの関数であり、ウィンドウを作成してジオメトリを追加します。 draw_geometriesをlop内に置くと、同時に多くのウィンドウが作成され、問題が発生する可能性があります。

回避策は、Visualizer()クラスを定義し、内部関数を使用することです。 non_blocking_visualisation.pyを使用した例を見てみましょう。

    vis = Visualizer()
    vis.create_window()
    vis.add_geometry(source)
    vis.add_geometry(target)
    threshold = 0.05
    icp_iteration = 100
    save_image = False

    ##################
    # this is to display the second example
    vis2 = Visualizer()
    vis2.create_window()
    vis2.add_geometry(source) # replace your geometry
    ##################

    for i in range(icp_iteration):
        reg_p2l = registration_icp(source, target, threshold,
                np.identity(4), TransformationEstimationPointToPlane(),
                ICPConvergenceCriteria(max_iteration = 1))
        source.transform(reg_p2l.transformation)
        vis.update_geometry()
        vis.poll_events()
        vis.update_renderer()

        ##################
        # this is to display the second example
        vis2.update_geometry()
        vis2.poll_events()
        vis2.update_renderer()
        ##################

        if save_image:
            vis.capture_screen_image("temp_%04d.jpg" % i)
    vis.destroy_window()
    vis2.destroy_window()

このスクリプトは、グリッチのない2つの画面を表示します。

申し訳ありませんが、はっきりしていなかったと思います。 デバッグの目的で、インタラクティブプロンプトからdraw_geometries()を呼び出すだけです。 これにより、ブレークポイントで停止しているときに、中間操作が意図したとおりに機能することを確認し、インタラクティブに検査できます。 draw_geometries()を、numpy配列から多数の点群を作成し、いくつかのマーカーを追加できる関数でラップしました。 インタラクティブなデバッグに非常に便利です。 問題は、この関数を使用すると、ノンブロッキングの視覚化が機能しなくなることです。

例をありがとう。 この例では、両方のウィンドウを操作できることがわかります。 これはいい。
そこで、コードをユースケースに再パックし、以下のテストを作成しました。

from open3d import *
import numpy as np
import copy


def show_drawings(source):

    vis2 = Visualizer()
    vis2.create_window(window_name='window2',width=640, height=480)
    vis2.add_geometry(source) # replace your geometry
    e = True
    while e:        
        vis2.update_geometry()
        e = vis2.poll_events()
        vis2.update_renderer()
    #vis2.destroy_window()                        
    return

if __name__ == "__main__":
    set_verbosity_level(VerbosityLevel.Debug)
    source_raw = read_point_cloud("../../TestData/ICP/cloud_bin_0.pcd")
    target_raw = read_point_cloud("../../TestData/ICP/cloud_bin_1.pcd")
    source = voxel_down_sample(source_raw, voxel_size = 0.02)
    target = voxel_down_sample(target_raw, voxel_size = 0.02)
    trans = [[0.862, 0.011, -0.507,  0.0],
            [-0.139, 0.967, -0.215,  0.7],
            [0.487, 0.255,  0.835, -1.4],
            [0.0, 0.0, 0.0, 1.0]]
    source.transform(trans)

    flip_transform = [[1, 0, 0, 0],
            [0, -1, 0, 0],
            [0, 0, -1, 0],
            [0, 0, 0, 1]]
    source.transform(flip_transform)
    target.transform(flip_transform)



    vis = Visualizer()
    vis.create_window(window_name='window1',width=640, height=480)                         
    vis.add_geometry(source)
    vis.add_geometry(target)
    threshold = 0.05
    icp_iteration = 100
    save_image = False    

    for i in range(icp_iteration):
        reg_p2l = registration_icp(source, target, threshold,
                np.identity(4), TransformationEstimationPointToPlane(),
                ICPConvergenceCriteria(max_iteration = 1))
        source.transform(reg_p2l.transformation)
        vis.update_geometry()
        vis.poll_events()
        vis.update_renderer()

        #At some point, while running, set a breakpoint here 
        #and in the interactive prompt call: show_drawings(source)
        #after inspecting, press ESC to close the window, 
        #and continue with the script.

        if save_image:
            vis.capture_screen_image("temp_%04d.jpg" % i)
    vis.destroy_window()

私が探していたのは、「ifsave_image」行のブレークポイントでコードを停止できることです。 次に、この行の上のコメントで説明されているように、インタラクティブなプロンプトでshow_drawings(source)を呼び出します。 点群を検査します。 ESCを押してウィンドウを閉じます。 その後、スクリプトの実行を続行します。 ただし、何らかの理由で、window2を閉じるときに、ESCを押すと、window1も閉じられます。 次回window1を使用すると、「GLFWエラー:GLFWライブラリが初期化されていません」と表示されます。

私が意図していることをどのように行うかについて何か考えはありますか?

同じ症状が見られます。 glfwウィンドウクローズイベントがすべてのウィンドウにブロードキャストされているようですが、これを修正する方法がまだ見つかりませんでした。

次のようにdel vis追加します。

vis.destroy_window()
del vis
このページは役に立ちましたか?
0 / 5 - 0 評価

関連する問題

DKandrew picture DKandrew  ·  4コメント

Prakash19921206 picture Prakash19921206  ·  4コメント

marcel-bariou picture marcel-bariou  ·  3コメント

mike239x picture mike239x  ·  4コメント

masonsun picture masonsun  ·  3コメント