Skip to content

Commit

Permalink
update all calls to use util
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay-krishnan committed Aug 13, 2023
1 parent 8cf9369 commit fd87d9b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
3 changes: 2 additions & 1 deletion gtsfm/loader/loader_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import gtsfm.common.types as gtsfm_types
import gtsfm.utils.images as img_utils
import gtsfm.utils.io as io_utils
import gtsfm.utils.io as io_utils
from gtsfm.common.image import Image
from gtsfm.common.pose_prior import PosePrior
from gtsfm.ui.gtsfm_process import GTSFMProcess, UiMetadata
Expand Down Expand Up @@ -415,7 +416,7 @@ def get_images_with_exif(self, search_path: str) -> Tuple[List[str], int]:
The number of all the images.
]
"""
all_image_paths = glob.glob(search_path)
all_image_paths = io_utils.get_sorted_image_names_in_dir(search_path)
num_all_imgs = len(all_image_paths)
exif_image_paths = []
for single_img_path in all_image_paths:
Expand Down
10 changes: 1 addition & 9 deletions gtsfm/loader/olsson_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
from gtsfm.common.image import Image
from gtsfm.loader.loader_base import LoaderBase

IMG_EXTENSIONS = ["png", "PNG", "jpg", "JPG"]


class OlssonLoader(LoaderBase):
"""Simple loader class that reads any of Carl Olsson's datasets from a folder on disk.
Expand Down Expand Up @@ -60,13 +58,7 @@ def __init__(
self._use_gt_extrinsics = use_gt_extrinsics
self._max_frame_lookahead = max_frame_lookahead

self._image_paths = []
for extension in IMG_EXTENSIONS:
search_path = os.path.join(folder, "images", f"*.{extension}")
self._image_paths.extend(glob.glob(search_path))

# sort the file names
self._image_paths.sort()
self._image_paths = io_utils.get_sorted_image_names_in_dir(os.path.join(folder, "images"))
self._num_imgs = len(self._image_paths)

if self._num_imgs == 0:
Expand Down
4 changes: 2 additions & 2 deletions gtsfm/loader/one_d_sfm_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def __init__(
self._default_focal_length_factor = default_focal_length_factor

# Fetch all the file names in /images folder.
search_path = os.path.join(folder, "images", f"*.{image_extension}")
search_path = os.path.join(folder, "images")

if enable_no_exif:
self._image_paths = glob.glob(search_path)
self._image_paths = io_utils.get_sorted_image_names_in_dir(search_path)
else:
(self._image_paths, num_all_imgs) = self.get_images_with_exif(search_path)
logger.info("Read %d images with exif out of %d in total.", len(self._image_paths), num_all_imgs)
Expand Down
21 changes: 21 additions & 0 deletions gtsfm/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Authors: Ayush Baid, John Lambert
"""
import glob
import os
import pickle
from bz2 import BZ2File
Expand Down Expand Up @@ -33,6 +34,9 @@
logger = logger_utils.get_logger()


IMG_EXTENSIONS = ["png", "PNG", "jpg", "JPG"]


def load_image(img_path: str) -> Image:
"""Load the image from disk.
Expand Down Expand Up @@ -619,3 +623,20 @@ def read_point_cloud_from_ply(ply_fpath: str) -> Tuple[np.ndarray, np.ndarray]:
"""
pointcloud = open3d.io.read_point_cloud(ply_fpath)
return open3d_vis_utils.convert_colored_open3d_point_cloud_to_numpy(pointcloud)


def get_sorted_image_names_in_dir(dir_path: str) -> List[str]:
"""Finds all jpg and png images in directory and returns their names in sorted order.
Args:
dir_path: Path to directory containing images.
Returns:
image_paths: List of image names in sorted order.
"""
image_paths = []
for extension in IMG_EXTENSIONS:
search_path = os.path.join(dir_path, f"*.{extension}")
image_paths.extend(glob.glob(search_path))

return sorted(image_paths)

0 comments on commit fd87d9b

Please sign in to comment.