Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace glob with rglob #283 #284

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions hloc/extract_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pprint
import collections.abc as collections
import PIL.Image
import glob

from . import extractors, logger
from .utils.base_model import dynamic_load
Expand Down Expand Up @@ -176,11 +177,12 @@ def __init__(self, root, conf, paths=None):
if paths is None:
paths = []
for g in conf.globs:
paths += list(Path(root).glob('**/'+g))
paths += glob.glob(
(Path(root) / '**' / g).as_posix(), recursive=True)
if len(paths) == 0:
raise ValueError(f'Could not find any image in root: {root}.')
paths = sorted(list(set(paths)))
self.names = [i.relative_to(root).as_posix() for i in paths]
paths = sorted(set(paths))
self.names = [Path(p).relative_to(root).as_posix() for p in paths]
logger.info(f'Found {len(self.names)} images in root {root}.')
else:
if isinstance(paths, (Path, str)):
Expand Down
5 changes: 3 additions & 2 deletions hloc/pipelines/4Seasons/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
import logging
from pathlib import Path
import glob

from ...utils.read_write_model import qvec2rotmat, rotmat2qvec
from ...utils.read_write_model import Image, write_model, Camera
Expand All @@ -28,10 +29,10 @@ def get_timestamps(files, idx):

def delete_unused_images(root, timestamps):
"""Delete all images in root if they are not contained in timestamps."""
images = list(root.glob('**/*.png'))
images = glob.glob((root / '**/*.png').as_posix(), recursive=True)
deleted = 0
for image in images:
ts = image.stem
ts = Path(image).stem
if ts not in timestamps:
os.remove(image)
deleted += 1
Expand Down
6 changes: 4 additions & 2 deletions hloc/pipelines/RobotCar/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path
import argparse
import glob

from . import colmap_from_nvm
from ... import extract_features, match_features, triangulation
Expand All @@ -24,8 +25,9 @@ def generate_query_list(dataset, image_dir, path):
params = ['SIMPLE_RADIAL', w, h, fx, cx, cy, 0.0]
cameras[side] = [str(p) for p in params]

queries = sorted(image_dir.glob('**/*.jpg'))
queries = [str(q.relative_to(image_dir.parents[0])) for q in queries]
queries = glob.glob((image_dir / '**/*.jpg').as_posix(), recursive=True)
queries = [Path(q).relative_to(image_dir.parents[0]).as_posix()
for q in sorted(queries)]

out = [[q] + cameras[Path(q).parent.name] for q in queries]
with open(path, 'w') as f:
Expand Down