|
| 1 | +/* |
| 2 | + * Copyright (C) 2015, Simon Fuhrmann |
| 3 | + * TU Darmstadt - Graphics, Capture and Massively Parallel Computing |
| 4 | + * All rights reserved. |
| 5 | + * |
| 6 | + * This software may be modified and distributed under the terms |
| 7 | + * of the BSD 3-Clause license. See the LICENSE.txt file for details. |
| 8 | + */ |
| 9 | + |
| 10 | +#include <iomanip> |
| 11 | +#include <iostream> |
| 12 | +#include <cstdlib> |
| 13 | + |
| 14 | +#include "mvs/settings.h" |
| 15 | +#include "mvs/dmrecon.h" |
| 16 | +#include "core/scene.h" |
| 17 | +#include "core/view.h" |
| 18 | +#include "util/timer.h" |
| 19 | +#include "util/arguments.h" |
| 20 | +#include "util/system.h" |
| 21 | +#include "util/tokenizer.h" |
| 22 | +#include "util/file_system.h" |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +struct AppSettings |
| 27 | +{ |
| 28 | + std::string scene_path; |
| 29 | + std::string ply_dest = "recon"; |
| 30 | + int master_id = -1; |
| 31 | + std::vector<int> view_ids; |
| 32 | + int max_pixels = 1500000; |
| 33 | + bool force_recon = false; |
| 34 | + bool write_ply = false; |
| 35 | + mvs::Settings mvs; |
| 36 | +}; |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +int |
| 41 | +main (int argc, char** argv) |
| 42 | +{ |
| 43 | + if(argc<3){ |
| 44 | + std::cout<<"usage: scendir scale"<<std::endl; |
| 45 | + return -1; |
| 46 | + } |
| 47 | + |
| 48 | + AppSettings conf; |
| 49 | + |
| 50 | + // 场景文件夹 |
| 51 | + conf.scene_path = argv[1]; |
| 52 | + // 获取图像尺度 |
| 53 | + std::stringstream stream1(argv[2]); |
| 54 | + stream1>>conf.mvs.scale; |
| 55 | + |
| 56 | + /* Load MVE scene. */ |
| 57 | + core::Scene::Ptr scene; |
| 58 | + try |
| 59 | + { |
| 60 | + scene = core::Scene::create(conf.scene_path); |
| 61 | + scene->get_bundle(); |
| 62 | + } |
| 63 | + catch (std::exception& e) |
| 64 | + { |
| 65 | + std::cerr << "Error loading scene: " << e.what() << std::endl; |
| 66 | + return EXIT_FAILURE; |
| 67 | + } |
| 68 | + |
| 69 | + /* Settings for Multi-view stereo */ |
| 70 | + conf.mvs.writePlyFile = conf.write_ply; |
| 71 | + conf.mvs.plyPath = util::fs::join_path(conf.scene_path, conf.ply_dest); |
| 72 | + |
| 73 | + core::Scene::ViewList& views(scene->get_views()); |
| 74 | + if (conf.view_ids.empty()) |
| 75 | + { |
| 76 | + std::cout << "Reconstructing all views..." << std::endl; |
| 77 | + for(std::size_t i = 0; i < views.size(); ++i) |
| 78 | + conf.view_ids.push_back(i); |
| 79 | + } |
| 80 | + else |
| 81 | + { |
| 82 | + std::cout << "Reconstructing views from list..." << std::endl; |
| 83 | + } |
| 84 | + |
| 85 | + // 对于每一个视角单独进行重建 |
| 86 | + util::WallTimer timer; |
| 87 | + for (std::size_t i = 0; i < conf.view_ids.size(); ++i) |
| 88 | + { |
| 89 | + std::size_t id = conf.view_ids[i]; |
| 90 | + if (id >= views.size()) |
| 91 | + { |
| 92 | + std::cout << "Invalid ID " << id << ", skipping!" << std::endl; |
| 93 | + continue; |
| 94 | + } |
| 95 | + |
| 96 | + if (views[id] == nullptr || !views[id]->is_camera_valid()) |
| 97 | + continue; |
| 98 | + |
| 99 | + /* Setup MVS. */ |
| 100 | + mvs::Settings settings(conf.mvs); |
| 101 | + settings.refViewNr = id; |
| 102 | + |
| 103 | + std::string embedding_name = "depth-L" + util::string::get(settings.scale); |
| 104 | + if (!conf.force_recon && views[id]->has_image(embedding_name)) |
| 105 | + continue; |
| 106 | + |
| 107 | + try { |
| 108 | + // 重建场景 |
| 109 | + mvs::DMRecon recon(scene, settings); |
| 110 | + recon.start(); |
| 111 | + views[id]->save_view(); |
| 112 | + } |
| 113 | + catch (std::exception &err) |
| 114 | + { |
| 115 | + std::cerr << err.what() << std::endl; |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + |
| 120 | + std::cout << "Reconstruction took "<< timer.get_elapsed() << "ms." << std::endl; |
| 121 | + |
| 122 | + /* Save scene */ |
| 123 | + std::cout << "Saving views back to disc..." << std::endl;scene->save_views(); |
| 124 | + |
| 125 | + return EXIT_SUCCESS; |
| 126 | +} |
0 commit comments