53 std::vector<std::pair<image_t, image_t>> ReadStereoImagePairs(
54 const std::string&
path,
const Reconstruction& reconstruction) {
57 std::vector<std::pair<image_t, image_t>> stereo_pairs;
58 stereo_pairs.reserve(stereo_pair_lines.size());
60 for (
const auto& line : stereo_pair_lines) {
61 const std::vector<std::string> names =
StringSplit(line,
" ");
62 CHECK_EQ(names.size(), 2);
64 const Image* image1 = reconstruction.FindImageWithName(names[0]);
65 const Image* image2 = reconstruction.FindImageWithName(names[1]);
67 CHECK_NOTNULL(image1);
68 CHECK_NOTNULL(image2);
70 stereo_pairs.emplace_back(image1->ImageId(), image2->ImageId());
79 std::string input_path;
80 std::string output_path;
81 std::string image_ids_path;
82 std::string image_names_path;
88 "image_ids_path", &image_ids_path,
89 "Path to text file containing one image_id to delete per line");
91 "image_names_path", &image_names_path,
92 "Path to text file containing one image name to delete per line");
93 options.
Parse(argc, argv);
96 reconstruction.
Read(input_path);
98 if (!image_ids_path.empty()) {
101 for (
const auto& image_id_str : image_ids) {
102 if (image_id_str.empty()) {
106 const image_t image_id = std::stoi(image_id_str);
108 const auto&
image = reconstruction.
Image(image_id);
111 "Deleting image_id=%d, image_name=%s from reconstruction",
117 "WARNING: Skipping image_id=%s, because it does not "
118 "exist in the reconstruction",
119 image_id_str.c_str())
125 if (!image_names_path.empty()) {
128 for (
const auto& image_name : image_names) {
129 if (image_name.empty()) {
134 if (
image !=
nullptr) {
137 "Deleting image_id=%d, image_name=%s from reconstruction",
143 "WARNING: Skipping image_name=%s, because it does not "
144 "exist in the reconstruction",
151 reconstruction.
Write(output_path);
157 std::string input_path;
158 std::string output_path;
159 double min_focal_length_ratio = 0.1;
160 double max_focal_length_ratio = 10.0;
161 double max_extra_param = 100.0;
162 size_t min_num_observations = 10;
167 options.
AddDefaultOption(
"min_focal_length_ratio", &min_focal_length_ratio);
168 options.
AddDefaultOption(
"max_focal_length_ratio", &max_focal_length_ratio);
171 options.
Parse(argc, argv);
174 reconstruction.
Read(input_path);
176 const size_t num_reg_images = reconstruction.
NumRegImages();
178 reconstruction.
FilterImages(min_focal_length_ratio, max_focal_length_ratio,
181 std::vector<image_t> filtered_image_ids;
182 for (
const auto&
image : reconstruction.
Images()) {
183 if (
image.second.IsRegistered() &&
184 image.second.NumPoints3D() < min_num_observations) {
185 filtered_image_ids.push_back(
image.first);
189 for (
const auto image_id : filtered_image_ids) {
193 const size_t num_filtered_images =
196 std::cout <<
StringPrintf(
"Filtered %d images from a total of %d images",
197 num_filtered_images, num_reg_images)
200 reconstruction.
Write(output_path);
206 std::string input_path;
207 std::string output_path;
208 std::string stereo_pairs_list;
223 options.
Parse(argc, argv);
226 reconstruction.
Read(input_path);
228 const auto stereo_pairs =
229 ReadStereoImagePairs(stereo_pairs_list, reconstruction);
241 std::string input_path;
242 std::string output_path;
249 options.
Parse(argc, argv);
252 std::cerr <<
"ERROR: `input_path` is not a directory" <<
std::endl;
257 std::cerr <<
"ERROR: `output_path` is not a directory" <<
std::endl;
269 const size_t min_num_matches =
270 static_cast<size_t>(options.
mapper->min_num_matches);
271 database_cache.
Load(database, min_num_matches,
272 options.
mapper->ignore_watermarks,
273 options.
mapper->image_names);
281 reconstruction.
Read(input_path);
286 const auto mapper_options = options.
mapper->Mapper();
288 for (
const auto&
image : reconstruction.
Images()) {
289 if (
image.second.IsRegistered()) {
296 std::cout <<
" => Image sees " <<
image.second.NumVisiblePoints3D()
297 <<
" / " <<
image.second.NumObservations() <<
" points"
303 const bool kDiscardReconstruction =
false;
306 reconstruction.
Write(output_path);
312 std::string input_path;
313 std::string output_path;
314 std::string output_type =
"COLMAP";
315 std::string image_list_path;
316 std::string copy_policy =
"copy";
317 int num_patch_match_src_images = 20;
327 "{COLMAP, PMVS, CMP-MVS}");
330 "{copy, soft-link, hard-link}");
332 &num_patch_match_src_images);
343 options.
Parse(argc, argv);
349 reconstruction.
Read(input_path);
350 std::cout <<
StringPrintf(
" => Reconstruction with %d images and %d points",
355 std::vector<image_t> image_ids;
356 if (!image_list_path.empty()) {
358 for (
const auto& image_name : image_names) {
360 if (
image !=
nullptr) {
361 image_ids.push_back(
image->ImageId());
363 std::cout <<
"WARN: Cannot find image " << image_name <<
std::endl;
369 if (copy_policy ==
"copy") {
371 }
else if (copy_policy ==
"soft-link") {
373 }
else if (copy_policy ==
"hard-link") {
376 std::cerr <<
"ERROR: Invalid `copy_policy` - supported values are "
377 "{'copy', 'soft-link', 'hard-link'}."
382 std::unique_ptr<Thread> undistorter;
383 if (output_type ==
"COLMAP") {
385 undistort_camera_options, &reconstruction, *options.
image_path,
386 output_path, num_patch_match_src_images, copy_type, image_ids));
387 }
else if (output_type ==
"PMVS") {
391 }
else if (output_type ==
"CMP-MVS") {
396 std::cerr <<
"ERROR: Invalid `output_type` - supported values are "
397 "{'COLMAP', 'PMVS', 'CMP-MVS'}."
402 undistorter->Start();
409 std::string input_file;
410 std::string output_path;
428 options.
Parse(argc, argv);
435 std::vector<std::pair<std::string, Camera>> image_names_and_cameras;
438 std::ifstream file(input_file);
439 CHECK(file.is_open()) << input_file;
442 std::vector<std::string> lines;
443 while (std::getline(file, line)) {
451 std::stringstream line_stream(line);
454 std::string image_name;
455 std::getline(line_stream, image_name,
' ');
460 std::getline(line_stream, item,
' ');
462 std::cerr <<
"ERROR: Camera model " << item <<
" does not exist"
468 std::getline(line_stream, item,
' ');
471 std::getline(line_stream, item,
' ');
475 while (!line_stream.eof()) {
476 std::getline(line_stream, item,
' ');
477 camera.
Params().push_back(std::stold(item));
482 image_names_and_cameras.emplace_back(image_name, camera);
486 std::unique_ptr<Thread> undistorter;
489 image_names_and_cameras));
491 undistorter->Start();
498 std::string input_path;
499 std::string output_path;
500 std::string mesh_path;
507 options.
Parse(argc, argv);
510 std::cerr <<
"ERROR: `input_path` does not exist" <<
std::endl;
515 std::cerr <<
"ERROR: `mesh_path` does not exist" <<
std::endl;
524 std::cout <<
StringPrintf(
" => Reconstruction with %d images and %d points",
529 options.
texturing->meshed_file_path = mesh_path;
531 JoinPaths(output_path,
"textured_mesh.obj");
std::shared_ptr< core::Tensor > image
void SetWidth(const size_t width)
bool VerifyParams() const
void SetModelIdFromName(const std::string &model_name)
const std::vector< double > & Params() const
void SetHeight(const size_t height)
void Load(const Database &database, const size_t min_num_matches, const bool ignore_watermarks, const std::unordered_set< std::string > &image_names)
void EndReconstruction(const bool discard)
void BeginReconstruction(Reconstruction *reconstruction)
bool RegisterNextImage(const Options &options, const image_t image_id)
void AddRequiredOption(const std::string &name, T *option, const std::string &help_text="")
std::shared_ptr< TexturingOptions > texturing
void AddTexturingOptions()
void AddDefaultOption(const std::string &name, T *option, const std::string &help_text="")
std::shared_ptr< std::string > database_path
std::shared_ptr< IncrementalMapperOptions > mapper
void AddDatabaseOptions()
void Parse(const int argc, char **argv)
std::shared_ptr< std::string > image_path
size_t NumRegImages() const
void Write(const std::string &path) const
const std::unordered_map< image_t, class Image > & Images() const
std::vector< image_t > FilterImages(const double min_focal_length_ratio, const double max_focal_length_ratio, const double max_extra_param)
const class Image & Image(const image_t image_id) const
size_t NumPoints3D() const
const class Image * FindImageWithName(const std::string &name) const
void DeRegisterImage(const image_t image_id)
bool ExistsImage(const image_t image_id) const
void Read(const std::string &path)
void PrintMinutes() const
QTextStream & endl(QTextStream &stream)
static const std::string path
int RunImageUndistorter(int argc, char **argv)
int RunImageFilterer(int argc, char **argv)
int RunImageUndistorterStandalone(int argc, char **argv)
void StringTrim(std::string *str)
bool ExistsCameraModelWithName(const std::string &model_name)
int RunImageRectifier(int argc, char **argv)
void StringToLower(std::string *str)
int RunImageDeleter(int argc, char **argv)
int RunImageTexturer(int argc, char **argv)
std::vector< std::string > ReadTextFileLines(const std::string &path)
bool ExistsDir(const std::string &path)
bool ExistsFile(const std::string &path)
int RunImageRegistrator(int argc, char **argv)
void CreateDirIfNotExists(const std::string &path)
std::string JoinPaths(T const &... paths)
void PrintHeading1(const std::string &heading)
std::vector< std::string > StringSplit(const std::string &str, const std::string &delim)
std::string StringPrintf(const char *format,...)
std::string to_string(const T &n)