forked from MohammadAmmargk8497/PCD_Visualisation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
open.py
73 lines (50 loc) · 2.1 KB
/
open.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
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
import os
import open3d as o3d
import numpy as np
import sys
from transforms import build_se3_transform
from tqdm import tqdm
def read_lego_loam_data_file(map_path, keyframe_id):
filename = map_path + 'dump/' + keyframe_id + '/data'
with open(filename, 'r') as f:
lines = f.readlines()
odom = []
for i in range(7, 11):
row = [float(x) for x in lines[i].strip().split()]
# print(f'{i} {row}')
odom.append(row)
return np.array(odom)
def create_combined_ply_point_cloud(root_folder, output_ply_file, n):
# Check if the root folder path exists
if not os.path.exists(root_folder):
raise FileNotFoundError(f"The root folder '{root_folder}' does not exist.")
# Create an empty point cloud
T_static = build_se3_transform([0,0,0,0,0,1.57])
pcd_map = []
pcd1 = o3d.geometry.PointCloud()
# Iterate over subfolders in the root folder
for idx in tqdm(range(n)):
keyframe_id = str(idx).zfill(6)
odom = read_lego_loam_data_file(root_folder, keyframe_id)
odom = T_static @ odom
pcd = o3d.io.read_point_cloud(root_folder+ 'dump/' + keyframe_id + '/' + 'cloud.pcd')
pcd = np.asarray(pcd.points)
pcd = np.hstack([pcd, np.ones((pcd.shape[0], 1))])
#print(pcd.shape)
pcd_map.append(((odom @ pcd.T).T))
#pcd_map=np.append(((odom @ pcd.T).T), pcd_map)
pcd_map = np.vstack(pcd_map)
pcd_map = pcd_map[: , :-1]
print(pcd_map.shape)
# Save the combined point cloud in PLY format
pcd1.points = o3d.utility.Vector3dVector(pcd_map)
o3d.io.write_point_cloud(output_ply_file, pcd1)
if __name__ == "__main__":
if len(sys.argv) != 4:
print("Usage: python your_script.py path_arg1 path_arg2 path_arg3")
sys.exit(1)
root_folder_path = sys.argv[1]
output_ply_file_path= sys.argv[2]
n = int(sys.argv[3])
output_ply_file_path = output_ply_file_path + 'combined_point_cloud.ply'
create_combined_ply_point_cloud(root_folder_path, output_ply_file_path, n)