ccf點雲資料處理
阿新 • • 發佈:2019-01-06
儲存一下當時如何處理資料的
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')