1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
.. _interactive_visualization:
Interactive visualization
-------------------------------------
This tutorial introduces user interaction features of the visualizer window.
.. literalinclude:: ../../../examples/python/visualization/interactive_visualization.py
:language: python
:lineno-start: 27
:lines: 27-
:linenos:
This script executes two applications of user interaction: ``demo_crop_geometry`` and ``demo_manual_registration``.
.. _crop_geometry:
Crop geometry
``````````````````````````````````````
.. literalinclude:: ../../../examples/python/visualization/interactive_visualization.py
:language: python
:lineno-start: 37
:lines: 37-51
:linenos:
This function simply reads a point cloud and calls ``draw_geometries_with_editing``. This function provides vertex selection and cropping.
.. Note:: Open3D has a ``VisualizerWithEditing`` class that inherits ``Visualizer`` class. It adds graphic user interaction features. Likewise examples in :ref:`customized_visualization`, ``VisualizerWithEditing()`` can be explicitly used instead of ``draw_geometries_with_editing([pcd])``.
Once a geometry is displayed, press ``Y`` twice to align geometry with negative direction of y-axis. After adjusting viewing orientation, press ``K`` to lock screen and to switch to the selection mode.
.. image:: ../../_static/visualization/interactive_visualization/crop_lock.png
:width: 400px
.. Tip:: The practical step for selecting area is to align the geometry with arbitrary axis using orthographic projection model. This trick makes selection easier, because it avoids self-occlusion hassle due to perspective projection.
To select a region, use either ``mouse drag`` (rectangle selection) or ``ctrl + left mouse click`` (polygon selection). The below example shows a selected area using a polygon.
.. image:: ../../_static/visualization/interactive_visualization/crop_selection.png
:width: 400px
Note that the selected area is dark shaded. To keep the selected area and discard the rest, press ``C``. A dialog box appears, which can be used to save the cropped geometry. The cropping result is shown after saving.
.. image:: ../../_static/visualization/interactive_visualization/crop_save.png
:width: 200px
.. image:: ../../_static/visualization/interactive_visualization/crop_result.png
:width: 400px
To finish selection mode, press ``F`` to switch to freeview mode.
.. image:: ../../_static/visualization/interactive_visualization/crop_freeview.png
:width: 400px
.. _manual_registration:
Manual registration
`````````````````````````````````````````````
Select correspondences
=====================================
The following script registers two point clouds using point-to-point ICP. It gets initial alignment via user interaction.
.. literalinclude:: ../../../examples/python/visualization/interactive_visualization.py
:language: python
:lineno-start: 61
:lines: 61-76
:linenos:
The script reads two point clouds, and visualizes the point clouds before alignment.
.. image:: ../../_static/visualization/interactive_visualization/manual_icp_initial.png
:width: 400px
.. literalinclude:: ../../../examples/python/visualization/interactive_visualization.py
:language: python
:lineno-start: 52
:lines: 52-60
:linenos:
The function ``pick_points(pcd)`` makes an instance of ``VisualizerWithEditing``. To mimic ``draw_geometries``, it creates windows, adds the geometry, visualizes the geometry, and then terminates. A novel interface function from ``VisualizerWithEditing`` is ``get_picked_points()`` that returns the indices of user-picked vertices.
To pick a vertex, press ``shift + left click`` on a window. If a vertex is selected, the visualizer window overlays a sphere on a selected vertex. For example, after picking three vertices in the source point cloud, it shows:
.. image:: ../../_static/visualization/interactive_visualization/manual_icp_source.png
:width: 400px
This will print:
.. code-block:: sh
Picked point #58481 (2.14, 1.56, 1.53) to add in queue.
Picked point #77321 (2.86, 1.92, 1.09) to add in queue.
Picked point #42639 (3.28, 1.53, 1.45) to add in queue.
Press ``Q`` to close the window. The next step is to pick the same correspondences in the target point cloud. The color of the sphere helps to identify the same correspondence.
.. image:: ../../_static/visualization/interactive_visualization/manual_icp_target.png
:width: 400px
This will print:
.. code-block:: sh
Picked point #54028 (1.62, 1.81, 1.23) to add in queue.
Picked point #97115 (2.45, 2.19, 1.11) to add in queue.
Picked point #47467 (2.75, 1.71, 1.45) to add in queue.
.. Tip:: To get a good registration result, try to pick more than three points that are well-distributed in the scene. Using a vertex in the corner region is a good way to easily pick the right correspondence.
Registration using user correspondences
=======================================
.. literalinclude:: ../../../examples/python/visualization/interactive_visualization.py
:language: python
:lineno-start: 77
:lines: 77-110
:linenos:
The later part of the demo computes an initial transformation based on the user-provided correspondences. This script builds pairs of correspondences using ``Vector2iVector(corr)``. It utilizes ``TransformationEstimationPointToPoint.compute_transformation`` to compute the initial transformation from the correspondences. The initial transformation is refined using ``registration_icp``.
The registration result is as follows:
.. image:: ../../_static/visualization/interactive_visualization/manual_icp_alignment.png
:width: 400px
|