diff --git a/utils/las2text_mapper.py b/utils/las2text_mapper.py index 654ae163ffc545f2e6096e044f68ed7b0bb33370..addc94886b1315a428ce5a89d18adb1dae288527 100755 --- a/utils/las2text_mapper.py +++ b/utils/las2text_mapper.py @@ -1,10 +1,13 @@ +import argparse import glob import os -import pandas as pd +from multiprocessing import Pool + +import laspy import numpy as np +import pandas as pd from tqdm import tqdm -import laspy -import argparse + class Las2TextMapper: @@ -38,43 +41,42 @@ class Las2TextMapper: # get label points = np.hstack((points, las.label[..., None])) # get treeID - points = np.hstack((points, las.treeID[..., None])) + # points = np.hstack((points, las.treeID[..., None])) + points = np.hstack((points, las.instance_nr[..., None])) # put all together to pandas dataframe points = pd.DataFrame( points, - columns=['x', 'y', 'z', 'red', 'green', 'blue', 'label', 'treeID'] + columns=['x', 'y', 'z', 'red', 'green', 'blue', 'label', 'instance_nr'] + # columns=['x', 'y', 'z', 'red', 'green', 'blue', 'label', 'treeID'] ) return points def process_folder(self): - """process_folder. - - Args: - mode: train, test or validation - """ - # read all las files in the folder data_dir using glob list_of_files = glob.glob(self.data_dir + "/*.las", recursive=False) # if self.save_dir does not exist, create it if not os.path.exists(self.save_dir): os.makedirs(self.save_dir) - # iterate over all files - for filepath in tqdm(list_of_files): - if self.verbose: - print("Processing file: ", filepath) + # process each file in parallel + with Pool(8) as p: + result = list(tqdm(p.map(self.process_single_file, list_of_files), total=len(list_of_files))) + + def process_single_file(self, filepath): + if self.verbose: + print("Processing file: ", filepath) # read the las file - points = self.read_single_las(filepath) + points = self.read_single_las(filepath) # save the points as text file in self.save_dir - filepath = filepath.split("/")[-1].split(".")[0] - filepath = self.save_dir + "/" + filepath + filepath = filepath.split("/")[-1].split(".")[0] + filepath = os.path.join(self.save_dir, filepath) # save the points - points.to_csv(filepath + ".txt", sep=',', index=False, header=True) + points.to_csv(filepath + ".txt", sep=',', index=False, header=True) if __name__ == "__main__": # use argparse to get the data_dir and save_dir