#coding:utf-8
import time
filename="1.txt"
print ("the input file name is:%r." %filename)
start = time.time()
print ("open the file...")
file = open(filename,"r+")
count = 0
for line in file:
count=count+1
print ("size is %d" %count)
file.close()
#output = open("out.pcd","w+")
f_prefix = filename.split('.')[0]
output_filename = '{prefix}.pcd'.format(prefix=f_prefix)
print output_filename
output = open(output_filename,"w+")
list = ['# .PCD v.5 - Point Cloud Data file format\n','VERSION .5\n','FIELDS x y z rgb\n','SIZE 4 4 4 4\n','TYPE F F F U\n','COUNT 1 1 1 1\n']
output.writelines(list)
output.write('WIDTH ')
output.write(str(count))
output.write('\nHEIGHT')
output.write(str(1))
output.write('\nPOINTS ')
output.write(str(count))
output.write('\nDATA ascii\n')
file1 = open(filename,"r")
all = file1.read()
output.write(all)
output.close()
file1.close()
end = time.time()
print ("run time is: ", end-start)
rgb值是U类型
rgb = R<<16 | G<<8 | B | 1<<24 r,g,b =[0-255]