Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
nibio_graph_sem_seg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maciej Wielgosz
nibio_graph_sem_seg
Commits
0a932d4e
Commit
0a932d4e
authored
1 year ago
by
Maciej Wielgosz
Browse files
Options
Downloads
Patches
Plain Diff
updated for instance segmentation results
parent
7c9656f8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
utils/las2text_mapper.py
+21
-19
21 additions, 19 deletions
utils/las2text_mapper.py
with
21 additions
and
19 deletions
utils/las2text_mapper.py
+
21
−
19
View file @
0a932d4e
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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment