Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pinard Clement
drone-depth-validation-set
Commits
53dc93f6
Commit
53dc93f6
authored
Jan 12, 2021
by
Clément Pinard
Browse files
Add colmap resize model
parent
9f920739
Changes
4
Hide whitespace changes
Inline
Side-by-side
cli_utils.py
View file @
53dc93f6
...
...
@@ -136,6 +136,11 @@ def add_gt_options(parser):
help
=
'max depth for occlusion. Everything further will not be considered at infinity'
)
gt_parser
.
add_argument
(
'--eth3d_splat_radius'
,
default
=
0.01
,
type
=
float
,
help
=
'see splat radius for ETH3D'
)
im_size
=
parser
.
add_mutually_exclusive_group
()
im_size
.
add_argument
(
'--output_rescale'
,
type
=
float
,
default
=
1
,
help
=
'Rescale images for depth ground truth'
)
im_size
.
add_argument
(
'--output_width'
,
type
=
float
,
default
=
None
,
help
=
'width of output images and depth maps'
)
def
set_full_argparser
():
...
...
filter_colmap_model.py
View file @
53dc93f6
...
...
@@ -13,7 +13,7 @@ parser = ArgumentParser(description='Filter COLMAP model of a single video by di
parser
.
add_argument
(
'--input_images_colmap'
,
metavar
=
'FILE'
,
type
=
Path
,
required
=
True
,
help
=
'Input COLMAP images.bin or images.txt file to filter.'
)
parser
.
add_argument
(
'--metadata'
,
metavar
=
'FILE'
,
type
=
Path
,
required
=
True
,
parser
.
add_argument
(
'--metadata
_path
'
,
metavar
=
'FILE'
,
type
=
Path
,
required
=
True
,
help
=
'Metadata CSV file of filtered video'
)
parser
.
add_argument
(
'--output_images_colmap'
,
metavar
=
'FILE'
,
type
=
Path
,
required
=
True
,
help
=
'Output images.bin or images.txt file with filtered frame localizations'
)
...
...
@@ -291,7 +291,7 @@ def filter_colmap_model(input_images_colmap, output_images_colmap, metadata,
if
__name__
==
'__main__'
:
args
=
parser
.
parse_args
()
env
=
vars
(
args
)
metadata
=
pd
.
read_csv
(
args
.
metadata
).
set_index
(
"db_id"
,
drop
=
False
).
sort_values
(
"time"
)
metadata
=
pd
.
read_csv
(
args
.
metadata
_path
).
set_index
(
"db_id"
,
drop
=
False
).
sort_values
(
"time"
)
interpolated_frames
=
filter_colmap_model
(
metadata
=
metadata
,
**
env
)
with
open
(
args
.
interpolated_frames_list
,
"w"
)
as
f
:
f
.
write
(
"
\n
"
.
join
(
interpolated_frames
)
+
"
\n
"
)
resize_colmap_cameras.py
0 → 100644
View file @
53dc93f6
from
colmap_util
import
read_model
as
rm
from
argparse
import
ArgumentParser
,
ArgumentDefaultsHelpFormatter
from
path
import
Path
parser
=
ArgumentParser
(
description
=
'Resize cameras in a colmap model'
,
formatter_class
=
ArgumentDefaultsHelpFormatter
)
parser
.
add_argument
(
'-i'
,
'--input_cameras_colmap'
,
metavar
=
'FILE'
,
type
=
Path
,
required
=
True
,
help
=
'Input COLMAP cameras.bin or caameras.txt file to rescale or resize.'
)
parser
.
add_argument
(
'-o'
,
'--output_cameras_colmap'
,
metavar
=
'FILE'
,
type
=
Path
,
required
=
True
,
help
=
'Output images.bin or images.txt file with filtered frame localizations'
)
im_resize
=
parser
.
add_mutually_exclusive_group
()
im_resize
.
add_argument
(
'-w'
,
'--width'
,
type
=
float
,
default
=
None
,
help
=
'Output width of cameras every camera will have, '
'even though they are initially of different size. '
'Height reflect initial ratio'
)
im_resize
.
add_argument
(
'-r'
,
'--rescale'
,
type
=
float
,
default
=
1
,
help
=
'float to which each camera dimension will be multiplied. '
'As such, cameras ay have different widths'
)
def
resize_cameras
(
input_cameras
,
output_cameras
,
output_width
=
None
,
output_rescale
=
1
):
if
input_cameras
.
ext
==
".txt"
:
cameras
=
rm
.
read_images_text
(
input_cameras
)
elif
input_cameras
.
ext
==
".bin"
:
cameras
=
rm
.
read_images_binary
(
input_cameras
)
else
:
print
(
input_cameras
.
ext
)
cameras_rescaled
=
{}
for
i
,
c
in
cameras
.
items
():
if
output_width
is
not
None
:
output_rescale
=
output_width
/
c
.
width
output_width
=
c
.
width
*
output_rescale
output_height
=
c
.
height
*
output_rescale
output_params
=
c
.
params
single_focal
=
(
'SIMPLE'
in
c
.
model
)
or
(
'RADIAL'
in
c
.
model
)
output_params
[:
3
]
*=
output_rescale
if
not
single_focal
:
output_params
[
3
]
*=
output_rescale
cameras_rescaled
[
i
]
=
rm
.
Camera
(
id
=
c
.
id
,
model
=
c
.
model
,
width
=
output_width
,
height
=
output_height
,
params
=
c
.
params
)
rm
.
write_cameras_text
(
cameras_rescaled
,
output_cameras
)
if
__name__
==
'__main__'
:
args
=
parser
.
parse_args
()
resize_cameras
(
input_cameras
=
args
.
input_cameras_colmap
,
output_cameras
=
args
.
output_cameras_colmap
,
output_width
=
args
.
output_width
,
output_rescale
=
args
.
output_rescale
)
video_localization.py
View file @
53dc93f6
...
...
@@ -2,7 +2,7 @@ import numpy as np
from
path
import
Path
from
cli_utils
import
print_step
from
colmap_util.read_model
import
read_images_text
,
read_images_binary
import
colmap_util.read_model
as
rm
from
filter_colmap_model
import
filter_colmap_model
import
pandas
as
pd
import
add_video_to_db
as
avtd
...
...
@@ -10,11 +10,12 @@ import extract_pictures_from_model as epfm
import
convert_dataset
as
cd
import
generate_sky_masks
as
gsm
import
meshlab_xml_writer
as
mxw
import
resiz_colmap_cameras
as
rcc
def
is_video_in_model
(
video_name
,
colmap_model
,
metadata
):
mapped_images_ids
=
read_images_binary
(
colmap_model
/
"images.bin"
).
keys
()
mapped_images_ids
=
rm
.
read_images_binary
(
colmap_model
/
"images.bin"
).
keys
()
video_image_ids
=
metadata
[
"db_id"
]
return
sum
(
video_image_ids
.
isin
(
mapped_images_ids
))
>
0
...
...
@@ -189,6 +190,7 @@ def generate_GT(video_name, raw_output_folder, images_root_folder, video_frames_
viz_folder
,
kitti_format_folder
,
metadata_path
,
interpolated_frames_list
,
final_model
,
aligned_mlp
,
global_registration_matrix
,
occlusion_ply
,
splats_ply
,
output_rescale
,
output_width
,
eth3d
,
colmap
,
filter_models
=
True
,
step_index
=
None
,
video_index
=
None
,
num_videos
=
None
,
GT_already_done
=
False
,
save_space
=
False
,
inspect_dataset
=
False
,
**
env
):
...
...
@@ -213,7 +215,7 @@ def generate_GT(video_name, raw_output_folder, images_root_folder, video_frames_
print
(
"Creating GT on video {} [{}/{}]"
.
format
(
video_name
.
basename
(),
video_index
,
num_videos
))
i_pv
=
1
metadata
=
pd
.
read_csv
(
metadata_path
)
metadata
=
pd
.
read_csv
(
metadata_path
)
.
set_index
(
"db_id"
,
drop
=
False
).
sort_values
(
"time"
)
if
filter_models
:
print_step_pv
(
i_pv
,
"Filtering model to have continuous localization"
)
interpolated_frames
=
filter_colmap_model
(
input_images_colmap
=
final_model
/
"images_raw.txt"
,
...
...
@@ -226,7 +228,13 @@ def generate_GT(video_name, raw_output_folder, images_root_folder, video_frames_
(
final_model
/
"images_raw.txt"
).
copy
(
final_model
/
"images.txt"
)
interpolated_frames
=
[]
model_length
=
len
(
read_images_text
(
final_model
/
"images.txt"
))
(
final_model
/
"cameras.txt"
).
copy
(
final_model
/
"cameras_raw.txt"
)
rcc
.
resize_cameras
(
input_cameras
=
final_model
/
"cameras_raw.txt"
,
output_cameras
=
final_model
/
"cameras.txt"
,
output_width
=
output_width
,
output_rescale
=
output_rescale
)
model_length
=
len
(
rm
.
read_images_text
(
final_model
/
"images.txt"
))
if
model_length
<
2
:
return
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment