File: OfflineReconstruction.cpp

package info (click to toggle)
open3d 0.16.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 80,688 kB
  • sloc: cpp: 193,088; python: 24,973; ansic: 8,356; javascript: 1,869; sh: 1,473; makefile: 236; xml: 69
file content (173 lines) | stat: -rw-r--r-- 7,152 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// ----------------------------------------------------------------------------
// -                        Open3D: www.open3d.org                            -
// ----------------------------------------------------------------------------
// The MIT License (MIT)
//
// Copyright (c) 2018-2021 www.open3d.org
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// ----------------------------------------------------------------------------

#include "Config.h"
#include "LegacyReconstructionUtil.h"
#include "open3d/Open3D.h"

void PrintHelp() {
    using namespace open3d;

    PrintOpen3DVersion();
    // clang-format off
    utility::LogInfo("Usage:");
    utility::LogInfo("    > LegacyReconstruction [options]");
    utility::LogInfo("      Given an RGBD image sequence, perform the following steps:");
    utility::LogInfo("      1. Make fragments from the RGBD image sequence.");
    utility::LogInfo("      2. Register multiple fragments.");
    utility::LogInfo("      3. Refine rough registration.");
    utility::LogInfo("      4. Integrate the whole RGBD sequence to make final mesh or point clouds.");
    utility::LogInfo("      5. (Optional) Run slac optimization for fragments.");
    utility::LogInfo("      6. (Optional) Run slac integration for sequence.");
    utility::LogInfo("");
    utility::LogInfo("Basic options:");
    utility::LogInfo("    --config [path to config json file]");
    utility::LogInfo("    --default_dataset [(optional) default dataset to be used, only if the config file is not provided]");
    utility::LogInfo("                      [options: (lounge, bedroom, jack_jack), default: lounge]");
    utility::LogInfo("    --make");
    utility::LogInfo("    --register");
    utility::LogInfo("    --refine");
    utility::LogInfo("    --integrate");
    utility::LogInfo("    --slac");
    utility::LogInfo("    --slac_integrate");
    utility::LogInfo("    --debug_mode [turn on debug mode]");
    utility::LogInfo("");
}

int main(int argc, char* argv[]) {
    using namespace open3d;
    using namespace open3d::apps::offline_reconstruction;

    if (argc < 2 ||
        utility::ProgramOptionExistsAny(argc, argv, {"-h", "--help"})) {
        PrintHelp();
        return 1;
    }

    // Load dataset.
    Json::Value config;
    if (utility::ProgramOptionExists(argc, argv, "--config")) {
        bool ret;
        try {
            const std::string config_path = utility::GetProgramOptionAsString(
                    argc, argv, "--config", "");
            utility::LogInfo("Loading config file: {}", config_path);
            ret = ReadJsonFromFile(config_path, config);

        } catch (const std::exception& e) {
            utility::LogWarning("Failed to load config file: {}", e.what());
            return 1;
        }
        InitConfig(config);
        ret = CheckFolderStructure(config["path_dataset"].asString());
        if (!ret) {
            utility::LogWarning("Check folder structure failed.");
            return 1;
        }
    } else {
        config = DefaultDatasetLoader(utility::GetProgramOptionAsString(
                argc, argv, "--default_dataset", "lounge"));
    }

    if (utility::ProgramOptionExists(argc, argv, "--debug_mode")) {
        config["debug_mode"] = true;
    } else {
        config["debug_mode"] = false;
    }

    config["device"] =
            utility::GetProgramOptionAsString(argc, argv, "--device", "CPU:0");

    // Print configuration in console.
    utility::LogInfo("====================================");
    utility::LogInfo("Configuration");
    utility::LogInfo("====================================");
    for (Json::Value::const_iterator it = config.begin(); it != config.end();
         ++it) {
        utility::LogInfo("{}: {}", it.key().asString(), it->asString());
    }
    utility::LogInfo("====================================");

    // Init Reconstruction pipeline.
    ReconstructionPipeline pipeline(config);

    utility::Timer timer;
    std::array<double, 6> durations({0, 0, 0, 0, 0, 0});
    if (utility::ProgramOptionExists(argc, argv, "--make")) {
        timer.Start();
        pipeline.MakeFragments();
        timer.Stop();
        const double ms = timer.GetDurationInMillisecond();
        durations[0] = ms;
    }
    if (utility::ProgramOptionExists(argc, argv, "--register")) {
        timer.Start();
        pipeline.RegisterFragments();
        timer.Stop();
        const double ms = timer.GetDurationInMillisecond();
        durations[1] = ms;
    }
    if (utility::ProgramOptionExists(argc, argv, "--refine")) {
        timer.Start();
        pipeline.RefineRegistration();
        timer.Stop();
        const double ms = timer.GetDurationInMillisecond();
        durations[2] = ms;
    }
    if (utility::ProgramOptionExists(argc, argv, "--integrate")) {
        timer.Start();
        pipeline.IntegrateScene();
        timer.Stop();
        const double ms = timer.GetDurationInMillisecond();
        durations[3] = ms;
    }
    if (utility::ProgramOptionExists(argc, argv, "--slac")) {
        timer.Start();
        pipeline.SLAC();
        timer.Stop();
        const double ms = timer.GetDurationInMillisecond();
        durations[4] = ms;
    }
    if (utility::ProgramOptionExists(argc, argv, "--slac_integrate")) {
        timer.Start();
        pipeline.IntegrateSceneSLAC();
        timer.Stop();
        const double ms = timer.GetDurationInMillisecond();
        durations[5] = ms;
    }

    utility::LogInfo("====================================");
    utility::LogInfo("Elapsed time (in h:m:s)");
    utility::LogInfo("====================================");
    utility::LogInfo("Making fragments:      {}", DurationToHMS(durations[0]));
    utility::LogInfo("Register fragments:    {}", DurationToHMS(durations[1]));
    utility::LogInfo("Refining registration: {}", DurationToHMS(durations[2]));
    utility::LogInfo("Integrating frames:    {}", DurationToHMS(durations[3]));
    utility::LogInfo("SLAC:                  {}", DurationToHMS(durations[4]));
    utility::LogInfo("SLAC integration:      {}", DurationToHMS(durations[5]));

    return 0;
}