-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathicp.py
36 lines (26 loc) · 1.11 KB
/
icp.py
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
import open3d as o3d
import numpy as np
import copy
def draw_registration_result(source, target, transformation):
source_temp = copy.deepcopy(source)
target_temp = copy.deepcopy(target)
source_temp.paint_uniform_color([1, 0.706, 0])
target_temp.paint_uniform_color([0, 0.651, 0.929])
source_temp.transform(transformation)
o3d.visualization.draw_geometries([source_temp, target_temp])
def icp(source,target,trans_init=np.eye(4)):
sourcemesh=copy.deepcopy(source)
targetmesh=copy.deepcopy(target)
sourceply = o3d.geometry.PointCloud()
targetply = o3d.geometry.PointCloud()
sourcemesh.compute_vertex_normals()
targetmesh.compute_vertex_normals()
sourceply.points = sourcemesh.vertices
targetply.points = targetmesh.vertices
sourceply.normals = sourcemesh.vertex_normals
targetply.normals = targetmesh.vertex_normals
threshold = 0.02
reg_p2p = o3d.registration.registration_icp(
sourceply, targetply, threshold, trans_init,
o3d.registration.TransformationEstimationPointToPlane())
return reg_p2p.transformation