TXT生成PCD文件(Python实现)
代码功能:将保存点云信息的TXT文件转化为pcl可读的pcd文件。
'''
This code is transform .txt to the .pcd.
and this is the original point cloud
2019.5.23
'''
import os
import sys
import numpy as np
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
ROOT_DIR = os.path.dirname(os.path.dirname(BASE_DIR))
sys.path.append(BASE_DIR)
sys.path.append(ROOT_DIR)
ROOT_DIR = os.path.join(ROOT_DIR, 'pointnet(enhence_11)/sem_seg/log11')
colour_map = (255,0,0,
0,255,0,
0,0,255,
156,102,31,
255,192,203,
255,0,255,
0,255,255,
255,255,0,
51,161,201,
128,42,42,
48,128,20,
160,32,240,
255,128,0)
def creat_real_pcd(input_path, output_path):
# loda data
Full_Data = np.loadtxt(input_path)
# creat output file
if os.path.exists(output_path):
os.remove(output_path)
Output_Data = open(output_path, 'a')
# headers
Output_Data.write('# .PCD v0.7 - Point Cloud Data file format\nVERSION 0.7\nFIELDS x y z rgba\nSIZE 4 4 4 4\nTYPE F F F U\nCOUNT 1 1 1 1')
string = '\nWIDTH ' + str(Full_Data.shape[0])
Output_Data.write(string)
Output_Data.write('\nHEIGHT 1\nVIEWPOINT 0 0 0 1 0 0 0')
string = '\nPOINTS ' + str(Full_Data.shape[0])
Output_Data.write(string)
Output_Data.write('\nDATA ascii')
# pack RGB
for j in range(Full_Data.shape[0]):
R=Full_Data[j,3]
G=Full_Data[j,4]
B=Full_Data[j,5]
value = (int(R) << 16 | int(G) << 8 | int(B))
string = ('\n