Skip to content
Snippets Groups Projects
Commit 0a932d4e authored by Maciej Wielgosz's avatar Maciej Wielgosz
Browse files

updated for instance segmentation results

parent 7c9656f8
Branches master
No related tags found
No related merge requests found
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment