Skip to content

Commit fbebd4b

Browse files
Philippe RerolePhilippe Rerole
authored andcommitted
Renamed import_localized_images into import_images_list_with_poses
1 parent a6df093 commit fbebd4b

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

tools/kapture_import_localized_images.py renamed to tools/kapture_import_image_list_with_poses.py

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@
2626
from kapture.io.structure import delete_existing_kapture_files
2727
from kapture.utils.open_cv import import_opencv_camera_calibration
2828

29-
logger = logging.getLogger('import_localized_images')
29+
logger = logging.getLogger('import_image_list_with_poses')
3030

3131

32-
def import_localized_images(localized_file_path: str,
33-
images_dir_path: str,
34-
camera_calibration_file_path: str,
35-
kapture_path: str,
36-
force_overwrite_existing: bool = False,
37-
images_import_method: TransferAction = TransferAction.skip,
38-
do_not_import_images: bool = False) -> None:
32+
def import_image_list_with_poses(images_list_file_path: str,
33+
images_dir_path: str,
34+
camera_calibration_file_path: str,
35+
kapture_path: str,
36+
force_overwrite_existing: bool = False,
37+
images_import_method: TransferAction = TransferAction.skip,
38+
do_not_import_images: bool = False) -> None:
3939
"""
40-
Imports the list of images to a kapture. This creates only images and cameras.
40+
Imports the list of images with their poses to a kapture. This creates only images and cameras.
4141
42-
:param localized_file_path: file containing the list of localized images with their poses
43-
:param images_dir_path: top directory of the images path. If not defined, the images path in the localized file
42+
:param images_list_file_path: file containing the list of images with their poses
43+
:param images_dir_path: top directory of the images path. If not defined, the images path in the list file
4444
must be full path.
4545
:param camera_calibration_file_path: path to the calibration camera file in opencv format.
4646
If missing, will compute a simple camera model based on the images
@@ -49,8 +49,8 @@ def import_localized_images(localized_file_path: str,
4949
:param images_import_method: choose how to import actual image files.
5050
:param do_not_import_images: when true, do not import the image files.
5151
"""
52-
if not path.exists(localized_file_path):
53-
raise FileNotFoundError(localized_file_path)
52+
if not path.exists(images_list_file_path):
53+
raise FileNotFoundError(images_list_file_path)
5454
os.makedirs(kapture_path, exist_ok=True)
5555
delete_existing_kapture_files(kapture_path, force_erase=force_overwrite_existing)
5656

@@ -67,24 +67,24 @@ def import_localized_images(localized_file_path: str,
6767
filename_list: List[str] = []
6868
image_name_list: List[str] = []
6969

70-
logger.info(f'Loading data from {localized_file_path}')
70+
logger.info(f'Loading data from {images_list_file_path}')
7171
# Find the top directory of all image files
72-
with open(localized_file_path, 'rt') as file:
73-
localized_data = table_from_file(file)
74-
for localized_line in localized_data:
75-
image_path = localized_line[2]
72+
with open(images_list_file_path, 'rt') as file:
73+
images_list_data = table_from_file(file)
74+
for image_line in images_list_data:
75+
image_path = image_line[2]
7676
if not do_not_import_images and not images_dir_path and not path.isabs(image_path):
7777
raise ValueError(f'Can not import a relative image file without top directory: {image_path}')
7878
if not path.isabs(image_path) and images_dir_path:
7979
image_path = path.join(images_dir_path, image_path)
8080
filename_list.append(image_path)
8181
common_images_path = path.commonpath(filename_list)
8282

83-
# Parse localized data file
84-
with open(localized_file_path, 'rt') as file:
85-
localized_data = table_from_file(file)
86-
for localized_line in localized_data:
87-
timestamp, camera_id, image_path, qw, qx, qy, qz, tx, ty, tz = localized_line
83+
# Parse image list data file
84+
with open(images_list_file_path, 'rt') as file:
85+
images_list_data = table_from_file(file)
86+
for image_line in images_list_data:
87+
timestamp, camera_id, image_path, qw, qx, qy, qz, tx, ty, tz = image_line
8888
# Add top directory if necessary
8989
if not path.isabs(image_path) and images_dir_path:
9090
image_path = path.join(images_dir_path, image_path)
@@ -128,11 +128,12 @@ def import_localized_images(localized_file_path: str,
128128
kapture_to_dir(kapture_path, imported_kapture)
129129

130130

131-
def import_localized_images_command_line() -> None:
131+
def import_image_list_with_poses_command_line() -> None:
132132
"""
133-
Do the localized images import to kapture using the parameters given on the command line.
133+
Do the images list import to kapture using the parameters given on the command line.
134134
"""
135-
parser = argparse.ArgumentParser(description='import localized images (trajectory+images) to the kapture format.')
135+
parser = argparse.ArgumentParser(description='import images with their poses (trajectory+images)'
136+
' to the kapture format.')
136137
parser_verbosity = parser.add_mutually_exclusive_group()
137138
parser_verbosity.add_argument(
138139
'-v', '--verbose', nargs='?', default=logging.WARNING, const=logging.INFO,
@@ -143,13 +144,13 @@ def import_localized_images_command_line() -> None:
143144
parser.add_argument('-f', '--force', action='store_true', default=False,
144145
help='force delete output if already exists.')
145146
# import ###########################################################################################################
146-
parser.add_argument('-l', '--localized_file', required=True,
147-
help='path to localized images list file')
147+
parser.add_argument('-l', '--images_list_file', required=True,
148+
help='path to images (with their poses) list file')
148149
parser.add_argument('--top_dir_images', default='',
149150
help='path to top directory of images.'
150-
' Necessary only if the images path are relative in the localized file')
151+
' Necessary only if the images path are relative in the list file')
151152
parser.add_argument('-c', '--camera_model_file',
152-
help='path to opencv camera calibration YAML file.'
153+
help='path to opencv camera calibration YAML file. Must be in YAML 1.1.'
153154
'If missing, will make a model based on images')
154155
parser.add_argument('-k', '--kapture', required=True, help='kapture directory')
155156
parser.add_argument('--image_action', type=TransferAction, default=TransferAction.copy,
@@ -165,10 +166,10 @@ def import_localized_images_command_line() -> None:
165166
# also let kapture express its logs
166167
kapture.utils.logging.getLogger().setLevel(args.verbose)
167168

168-
import_localized_images(args.localized_file, args.top_dir_images, args.camera_model_file,
169-
args.kapture, args.force,
170-
args.image_action, args.do_not_import_images)
169+
import_image_list_with_poses(args.images_list_file, args.top_dir_images, args.camera_model_file,
170+
args.kapture, args.force,
171+
args.image_action, args.do_not_import_images)
171172

172173

173174
if __name__ == '__main__':
174-
import_localized_images_command_line()
175+
import_image_list_with_poses_command_line()

0 commit comments

Comments
 (0)