用python将.h5文件的数据转化成.pcd文件

import h5py
import numpy as np
import os
import math
from open3d import *

filename = '/home/jp/project/pointnet/sem_seg/indoor3d_sem_seg_hdf5_data/ply_data_all_0.h5'
f = h5py.File(filename, 'r')

index_start = 0
index_end = 1
data = f['data']
label = f['label']
one_data = data[index_start:index_end, :, :]
one_label = label[index_start:index_end]
one_data = np.concatenate(one_data, axis=0)
one_label = np.concatenate(one_label, axis=0)


data_shape = np.shape(one_data)

WIDTH = data_shape[0]
POINTS = WIDTH

# pack RGB
rgb = []
for i in range(POINTS):
	value = 0
	value += one_data[i, 3]*255*65536
	value += one_data[i, 4]*255*256
	value += one_data[i, 5]*255
	value = value + 16777216
	rgb.append(value)

path = '/home/jp/project/test/out/seg.pcd'
if os.path.exists(path):
	os.remove(path)

out = open(path, 'a')

# headers
out.write('# .PCD v.7 - Point Cloud Data file format\nVERSION .7\nFIELDS x y z rgb\nSIZE 4 4 4 4\nTYPE F F F U\nCOUNT 1 1 1 1')
string = '\nWIDTH ' + str(WIDTH)
out.write(string)
out.write('\nHEIGHT 1\nVIEWPOINT 0 0 -2 0 1 0 0')
string = '\nPOINTS ' + str(POINTS)
out.write(string)
out.write('\nDATA ascii')

#datas
for i in range(POINTS):
	string = '\n' + str(one_data[i, 0]) + ' ' + str(one_data[i, 1]) + ' ' +str(one_data[i, 2]) + ' ' + str(int(rgb[i]))
	out.write(string)


out.close()

 

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 12
    评论
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值