TXT生成PCD文件

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值