ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
image_reader.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <unordered_set>
11 
12 #include "base/database.h"
13 #include "util/bitmap.h"
14 #include "util/threading.h"
15 
16 namespace colmap {
17 
19  // Path to database in which to store the extracted data.
20  std::string database_path = "";
21 
22  // Root path to folder which contains the images.
23  std::string image_path = "";
24 
25  // Optional root path to folder which contains image masks. For a given
26  // image, the corresponding mask must have the same sub-path below this root
27  // as the image has below image_path. The filename must be equal, aside from
28  // the added extension .png. For example, for an image
29  // image_path/abc/012.jpg, the mask would be mask_path/abc/012.jpg.png. No
30  // features will be extracted in regions where the mask image is black
31  // (pixel intensity value 0 in grayscale).
32  std::string mask_path = "";
33 
34  // Optional list of images to read. The list must contain the relative path
35  // of the images with respect to the image_path.
36  std::vector<std::string> image_list;
37 
38  // Name of the camera model.
39  std::string camera_model = "SIMPLE_RADIAL";
40 
41  // Whether to use the same camera for all images.
42  bool single_camera = false;
43 
44  // Whether to use the same camera for all images in the same sub-folder.
46 
47  // Whether to use a different camera for each image.
49 
50  // Whether to explicitly use an existing camera for all images. Note that in
51  // this case the specified camera model and parameters are ignored.
53 
54  // Manual specification of camera parameters. If empty, camera parameters
55  // will be extracted from EXIF, i.e. principal point and focal length.
56  std::string camera_params = "";
57 
58  // If camera parameters are not specified manually and the image does not
59  // have focal length EXIF information, the focal length is set to the
60  // value `default_focal_length_factor * max(width, height)`.
62 
63  // Optional path to an image file specifying a mask for all images. No
64  // features will be extracted in regions where the mask is black (pixel
65  // intensity value 0 in grayscale).
66  std::string camera_mask_path = "";
67 
68  bool Check() const;
69 };
70 
71 // Recursively iterate over the images in a directory. Skips an image if it
72 // already exists in the database. Extracts the camera intrinsics from EXIF and
73 // writes the camera information to the database.
74 class ImageReader {
75 public:
76  enum class Status {
77  FAILURE,
78  SUCCESS,
84  };
85 
86  ImageReader(const ImageReaderOptions& options, Database* database);
87 
88  Status Next(Camera* camera, Image* image, Bitmap* bitmap, Bitmap* mask);
89  size_t NextIndex() const;
90  size_t NumImages() const;
91 
92 private:
93  // Image reader options.
94  ImageReaderOptions options_;
95  Database* database_;
96  // Index of previously processed image.
97  size_t image_index_;
98  // Previously processed camera.
99  Camera prev_camera_;
100  std::unordered_map<std::string, camera_t> camera_model_to_id_;
101  // Names of image sub-folders.
102  std::string prev_image_folder_;
103  std::unordered_set<std::string> image_folders_;
104 };
105 
106 } // namespace colmap
std::shared_ptr< core::Tensor > image
size_t NextIndex() const
ImageReader(const ImageReaderOptions &options, Database *database)
Definition: image_reader.cc:50
Status Next(Camera *camera, Image *image, Bitmap *bitmap, Bitmap *mask)
Definition: image_reader.cc:86
size_t NumImages() const
const camera_t kInvalidCameraId
Definition: types.h:75
std::vector< std::string > image_list
Definition: image_reader.h:36