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
No related branches found
No related tags found
No related merge requests found
import argparse
import glob import glob
import os import os
import pandas as pd from multiprocessing import Pool
import laspy
import numpy as np import numpy as np
import pandas as pd
from tqdm import tqdm from tqdm import tqdm
import laspy
import argparse
class Las2TextMapper: class Las2TextMapper:
...@@ -38,43 +41,42 @@ class Las2TextMapper: ...@@ -38,43 +41,42 @@ class Las2TextMapper:
# get label # get label
points = np.hstack((points, las.label[..., None])) points = np.hstack((points, las.label[..., None]))
# get treeID # 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 # put all together to pandas dataframe
points = pd.DataFrame( points = pd.DataFrame(
points, 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 return points
def process_folder(self): 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) list_of_files = glob.glob(self.data_dir + "/*.las", recursive=False)
# if self.save_dir does not exist, create it # if self.save_dir does not exist, create it
if not os.path.exists(self.save_dir): if not os.path.exists(self.save_dir):
os.makedirs(self.save_dir) os.makedirs(self.save_dir)
# iterate over all files # process each file in parallel
for filepath in tqdm(list_of_files): with Pool(8) as p:
if self.verbose: result = list(tqdm(p.map(self.process_single_file, list_of_files), total=len(list_of_files)))
print("Processing file: ", filepath)
def process_single_file(self, filepath):
if self.verbose:
print("Processing file: ", filepath)
# read the las file # 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 # save the points as text file in self.save_dir
filepath = filepath.split("/")[-1].split(".")[0] filepath = filepath.split("/")[-1].split(".")[0]
filepath = self.save_dir + "/" + filepath filepath = os.path.join(self.save_dir, filepath)
# save the points # 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__": if __name__ == "__main__":
# use argparse to get the data_dir and save_dir # 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