在处理工作时遇到需要将大幅点云分块处理的情况,记录处理过程代码:
import numpy as np
import open3d
import pandas as pd
import glob,os
from os.path import join, exists, dirname, abspath,basename
from math import *
import sys
BASE_DIR = dirname(abspath(__file__))
ROOT_DIR = dirname(BASE_DIR)
sys.path.append(BASE_DIR)
sys.path.append(ROOT_DIR)
for sel_path in glob.glob(join("result","*.txt")):
print(sel_path)
filename=basename(sel_path)[:-4]
np_data=pd.read_csv(sel_path,delim_whitespace=True)
data_file=np_data.values
jilu=np.zeros(data_file.shape[0])
maxx=max(data_file[:,0])
minx=min(data_file[:,0])
chax=(maxx-minx)/4
maxy=max(data_file[:, 1])
miny=min(data_file[:, 1])
chay = (maxy-miny)/4
for kk in range(data_file.shape[0]):
xx=((data_file[kk,0]-minx)//chax)
yy = ((data_file[kk, 1] - miny) // chay)
jilu[kk]=xx*4+yy
for i in range(16):
jj=data_file[jilu==i]
if np.sum(jj[:,6])<1000:
continue
filename_16=filename+"_{:.2f}.txt".format(i)
outpath=join("out_16",filename_16)
np.savetxt(outpath,jj)
print(outpath)