欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ccf点云数据处理

程序员文章站 2022-06-02 21:51:36
...

保存一下当时如何处理数据的

1.将csv文件存储为h5文件

import numpy as np
import h5py
L0 = np.loadtxt(open(".\category0.csv","rb"),delimiter=",",skiprows=0)
L1 = np.loadtxt(open(".\category1.csv","rb"),delimiter=",",skiprows=0)
L2 = np.loadtxt(open(".\category2.csv","rb"),delimiter=",",skiprows=0)
L3 = np.loadtxt(open(".\category3.csv","rb"),delimiter=",",skiprows=0)

L0 = L0[0:(len(L0)//2048*2048)]#就要2048列
L0 = np.reshape(L0,(-1,2048))
L1 = L1[0:(len(L1)//2048*2048)]#就要2048列
L1 = np.reshape(L1,(-1,2048))
L2 = L2[0:(len(L2)//2048*2048)]#就要2048列
L2 = np.reshape(L2,(-1,2048))
L3 = L3[0:(len(L3)//2048*2048)]#就要2048列
L3 = np.reshape(L3,(-1,2048))

L = np.r_[L0,L1]
L = np.r_[L,L2]
L = np.r_[L,L3]

f = h5py.File('allpts.h5','w') #创建h5文件,文件指针f
f['data'] = [i[0:3] for i in L]
f['labels'] = [i[3] for i in L]
f.close()
print('end')

2.读取文件,多个文件把同一类别的整理在一起

import numpy as np
import pandas as pd
import h5py
import os
rootdir = '.\\training\\pts'
categorydir = '.\\training\\category'
list = os.listdir(rootdir)#得到路径下文件名
pstList = [] #坐标数据集
categoryList = [] #标签数据集
for i in range (0,len(list)):  #for i in range(0,len(list)): #所有文件名字
        path = os.path.join(rootdir,list[i]) #pts加上文件名
        categorypath = os.path.join(categorydir,list[i])#类别的路径
        if os.path.isfile(path):
            tup = pd.read_csv(path,header=None) #读取一个存三维坐标的csv文件
            if len(pstList) == 0:
                pstList = tup.values
            else:
                pstList = np.r_[pstList,tup.values] #增加行
                
            categorytup = pd.read_csv(categorypath,header=None)#读取标识类别的csv文件
            if len(categoryList) == 0:
                categoryList = categorytup.values
            else:
                categoryList = np.r_[categoryList,categorytup.values]
List = np.c_[pstList,categoryList] #把数据和标签合起来,最后一列是标签
L0 = []
L1 = []
L2 = []
L3 = []

for i in range(0,len(List)):
    if List[i][3] == 0:
        L0 = L0 + [List[i]]
    elif List[i][3] == 1:
        L1 = L1 + [List[i]]
    elif List[i][3] == 2:
        L2 = L2 + [List[i]]
    elif List[i][3] == 3:
        L3 = L3 + [List[i]]
  
if len(L0)>0:
    np.savetxt('category0.csv',L0,delimiter=',') 
if len(L1)>0:
    np.savetxt('category1.csv',L1,delimiter=',') 
if len(L2)>0:
    np.savetxt('category2.csv',L2,delimiter=',') 
if len(L3)>0:
    np.savetxt('category3.csv',L3,delimiter=',') 
    
print('end')
相关标签: ccf