add code snippet to normalize geometry
This commit is contained in:
parent
cd251d6c40
commit
760e44456a
1 changed files with 16 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import json
|
import json
|
||||||
import copy
|
import copy
|
||||||
|
import open3d as o3d
|
||||||
|
|
||||||
|
|
||||||
def get_tf_cams(cam_dict, target_radius=1.):
|
def get_tf_cams(cam_dict, target_radius=1.):
|
||||||
|
@ -27,12 +28,26 @@ def get_tf_cams(cam_dict, target_radius=1.):
|
||||||
return translate, scale
|
return translate, scale
|
||||||
|
|
||||||
|
|
||||||
def normalize_cam_dict(in_cam_dict_file, out_cam_dict_file, target_radius=1.):
|
def normalize_cam_dict(in_cam_dict_file, out_cam_dict_file, target_radius=1., in_geometry_file=None, out_geometry_file=None):
|
||||||
with open(in_cam_dict_file) as fp:
|
with open(in_cam_dict_file) as fp:
|
||||||
in_cam_dict = json.load(fp)
|
in_cam_dict = json.load(fp)
|
||||||
|
|
||||||
translate, scale = get_tf_cams(in_cam_dict, target_radius=target_radius)
|
translate, scale = get_tf_cams(in_cam_dict, target_radius=target_radius)
|
||||||
|
|
||||||
|
if in_geometry_file is not None and out_geometry_file is not None:
|
||||||
|
# check this page if you encounter issue in file io: http://www.open3d.org/docs/0.9.0/tutorial/Basic/file_io.html
|
||||||
|
geometry = o3d.io.read_triangle_mesh(in_geometry_file)
|
||||||
|
|
||||||
|
tf_translate = np.eye(4)
|
||||||
|
tf_translate[:3, 3:4] = translate
|
||||||
|
tf_scale = np.eye(4)
|
||||||
|
tf_scale[:3, :3] *= scale
|
||||||
|
tf = np.matmul(tf_scale, tf_translate)
|
||||||
|
|
||||||
|
geometry_norm = geometry.transform(tf)
|
||||||
|
o3d.io.write_triangle_mesh(out_geometry_file, geometry_norm)
|
||||||
|
|
||||||
|
mesh_norm = mesh.transform(tf)
|
||||||
def transform_pose(W2C, translate, scale):
|
def transform_pose(W2C, translate, scale):
|
||||||
C2W = np.linalg.inv(W2C)
|
C2W = np.linalg.inv(W2C)
|
||||||
cam_center = C2W[:3, 3]
|
cam_center = C2W[:3, 3]
|
||||||
|
|
Loading…
Reference in a new issue