如何将.pts或.npy文件转换为.ply或.h5文件? [英] how to convert .pts or .npy file into .ply or .h5 file?

查看:1333
本文介绍了如何将.pts或.npy文件转换为.ply或.h5文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3d点云数据作为.npy文件和.pts数据.

I have 3d point cloud data as .npy file and .pts data.

要将这些数据用于3d分类神经网络,我必须将这些数据更改为.h5文件.

To use these data for 3d classification neural net, I have to change these data to .h5 file.

因此,首先,我尝试使用python将.npy或.pts文件转换为.ply文件.

So, first I am trying to convert .npy or .pts file to .ply file using python.

您能参考我的示例代码还是帮助我转换文件格式?

Could you refer to me example codes or help me for converting file format?

此外,我非常感谢将.ply转换为.h5格式的方法.

Also, I will really appreciate for ways to convert .ply to .h5 format..

对不起,我的英语水平很差.

Sorry for my poor english skills.

推荐答案

我希望这段代码能帮助您入门,它展示了如何从npy(或随机点)创建h5文件.警告组和数据集的名称是任意的(这是一个示例).

I hope this code will get you started, it shows how to create a h5 file from a npy (or random points). Warning the name of group and dataset are arbitrary (it's an example).

import os
import h5py
import numpy as np

# reading or creating an array of points numpy style
def create_or_load_random_points_npy(file_radix, size, min, max):
    if os.path.exists(file_radix+'.npy'):
        arr = np.load(file_radix+'.npy')
    else:
        arr = np.random.uniform(min, max, (size,3))
        np.save(file_radix, arr)
    return arr


# converting a numpy array (size,3) to a h5 file with two groups representng two way
# of serializing points
def convert_array_2_shades_of_grey(file_radix, arr):
    file = h5py.File(file_radix + '.h5', 'w')
    #only one dataset in a group
    group = file.create_group("single_dataset")
    group.attrs["desc"]=np.string_("random points in a single dataset")
    dset=group.create_dataset("points", (len(arr), len(arr[0])), h5py.h5t.NATIVE_DOUBLE)
    dset[...]=arr
    #create a dataset for each coordinate
    group = file.create_group("several_datasets")
    group.attrs["desc"] = np.string_("random points in a several coordinates (one for each coord)")
    dset = group.create_dataset("x", (len(arr),), h5py.h5t.NATIVE_DOUBLE)
    dset[...] = arr[:, 0]
    dset = group.create_dataset("y", (len(arr),), h5py.h5t.NATIVE_DOUBLE)
    dset[...] = arr[:, 1]
    dset = group.create_dataset("z", (len(arr),), h5py.h5t.NATIVE_DOUBLE)
    dset[...] = arr[:, 2]

# loads the h5 file, choose which way of storing you would like to deserialize
def load_random_points_h5(file_radix, single=True):
    file = h5py.File(file_radix + '.h5', 'r')
    if single:
        group = file["single_dataset"]
        print 'reading -> ', group.attrs["desc"]
        dset=group["points"]
        arr = dset[...]
    else:
        group = file["several_datasets"]
        print 'reading -> ', group.attrs["desc"]
        dset = group["x"]
        arr = np.zeros((dset.size, 3))
        arr[:, 0] = dset[...]
        dset = group["y"]
        arr[:, 1] = dset[...]
        dset = group["z"]
        arr[:, 2] = dset[...]
    return arr

# And now we test !!!
file_radix = 'test'
# create or load the npy file
arr =  create_or_load_random_points_npy(file_radix, 10000, -100.0, 100.0)
# Well, well, what is in the box ?
print arr

# converting numpy array to h5
convert_array_2_shades_of_grey(file_radix, arr)

# loading single dataset style.
arr = load_random_points_h5(file_radix, True)
# Well, well, what is in the box ?
print arr
# loading several dataset style.
arr = load_random_points_h5(file_radix, False)
# Well, well, what is in the box ?
print arr

要查看h5文件的内容,请下载 HDFview .

To view the content of the h5 file, download HDFview.

也不要犹豫,查看 h5py文档.

最后但并非最不重要的一点是,您始终可以在

And last but not least, you can always ask question to the HDF5 community at HDFgroup forum (they deliver shiny badges like SO, waouh !!!)

这篇关于如何将.pts或.npy文件转换为.ply或.h5文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆