1# ----------------------------------------------------------------------------
2# - Open3D: www.open3d.org -
3# ----------------------------------------------------------------------------
4# The MIT License (MIT)
5#
6# Copyright (c) 2018-2021 www.open3d.org
7#
8# Permission is hereby granted, free of charge, to any person obtaining a copy
9# of this software and associated documentation files (the "Software"), to deal
10# in the Software without restriction, including without limitation the rights
11# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12# copies of the Software, and to permit persons to whom the Software is
13# furnished to do so, subject to the following conditions:
14#
15# The above copyright notice and this permission notice shall be included in
16# all copies or substantial portions of the Software.
17#
18# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24# IN THE SOFTWARE.
25# ----------------------------------------------------------------------------
26
27import numpy as np
28import open3d as o3d
29
30if __name__ == "__main__":
31
32 print("Load two aligned point clouds.")
33 demo_data = o3d.data.DemoFeatureMatchingPointClouds()
34 pcd0 = o3d.io.read_point_cloud(demo_data.point_cloud_paths[0])
35 pcd1 = o3d.io.read_point_cloud(demo_data.point_cloud_paths[1])
36
37 pcd0.paint_uniform_color([1, 0.706, 0])
38 pcd1.paint_uniform_color([0, 0.651, 0.929])
39 o3d.visualization.draw_geometries([pcd0, pcd1])
40 print("Load their FPFH feature and evaluate.")
41 print("Black : matching distance > 0.2")
42 print("White : matching distance = 0")
43 feature0 = o3d.io.read_feature(demo_data.fpfh_feature_paths[0])
44 feature1 = o3d.io.read_feature(demo_data.fpfh_feature_paths[1])
45
46 fpfh_tree = o3d.geometry.KDTreeFlann(feature1)
47 for i in range(len(pcd0.points)):
48 [_, idx, _] = fpfh_tree.search_knn_vector_xd(feature0.data[:, i], 1)
49 dis = np.linalg.norm(pcd0.points[i] - pcd1.points[idx[0]])
50 c = (0.2 - np.fmin(dis, 0.2)) / 0.2
51 pcd0.colors[i] = [c, c, c]
52 o3d.visualization.draw_geometries([pcd0])
53 print("")
54
55 print("Load their L32D feature and evaluate.")
56 print("Black : matching distance > 0.2")
57 print("White : matching distance = 0")
58 feature0 = o3d.io.read_feature(demo_data.l32d_feature_paths[0])
59 feature1 = o3d.io.read_feature(demo_data.l32d_feature_paths[1])
60
61 fpfh_tree = o3d.geometry.KDTreeFlann(feature1)
62 for i in range(len(pcd0.points)):
63 [_, idx, _] = fpfh_tree.search_knn_vector_xd(feature0.data[:, i], 1)
64 dis = np.linalg.norm(pcd0.points[i] - pcd1.points[idx[0]])
65 c = (0.2 - np.fmin(dis, 0.2)) / 0.2
66 pcd0.colors[i] = [c, c, c]
67 o3d.visualization.draw_geometries([pcd0])
68 print("")