in lib/Importer.cpp [25:195]
void DepthVideoImporter::importVideo(
DepthVideo& video, const std::string& path, const bool discoverStreams) {
LOG(INFO) << "Importing 3D video '" << path << "'...";
// Import frame metadata
std::vector<std::unique_ptr<MetaFrame>> frames;
int width = -1;
int height = -1;
importMetaFrames(path, width, height, frames);
video.init(path, width, height, std::move(frames));
if (!discoverStreams) {
return;
}
LOG(INFO) << " Discovering color streams...";
using ColorStreamDesc =
std::tuple<std::string, std::string, std::string, int>;
std::vector<ColorStreamDesc> colorStreams {
{"color_full", "full", ".png", CV_32FC3},
{"color_down", "down", ".raw", CV_32FC3},
{"color_down_png", "down_png", ".png", CV_32FC3},
{"dynamic_mask", "dynamic_mask", ".png", CV_8UC1},
};
for (const ColorStreamDesc& colorStreamDesc : colorStreams) {
const std::string& dir = std::get<0>(colorStreamDesc);
const std::string& name = std::get<1>(colorStreamDesc);
const std::string& extension = std::get<2>(colorStreamDesc);
const int type = std::get<3>(colorStreamDesc);
const std::string path = video.path() + "/" + dir;
if (fs::is_directory(path)) {
LOG(INFO) << " Found color stream '" << dir << "'.";
video.createColorStream(name, dir, extension, type);
}
}
std::vector<std::string> colorStreamCheckPaths;
for (auto& entry :
boost::make_iterator_range(fs::directory_iterator(video.path()), {})) {
if (fs::is_directory(entry)) {
colorStreamCheckPaths.push_back(entry.path().string());
}
}
std::sort(colorStreamCheckPaths.begin(), colorStreamCheckPaths.end());
for (const std::string& colorPath : colorStreamCheckPaths) {
LOG(INFO) << " Checking '" << colorPath << "'.";
std::string relativePath = fs::relative(colorPath, video.path()).string();
// Skip hardcoded streams.
bool skip = false;
for (const ColorStreamDesc& colorStreamDesc : colorStreams) {
if (std::get<1>(colorStreamDesc) == relativePath) {
skip = true;
break;
}
}
if (skip) {
continue;
}
std::string infoFile = colorPath + "/stream_info.txt";
if (!fs::exists(infoFile)) {
continue;
}
std::ifstream is(infoFile, std::ios::binary);
if (is.fail()) {
throw std::runtime_error("Could not open frame file.");
}
std::string type;
is >> type;
if (type != "color") {
continue;
}
std::string extension;
is >> extension;
std::string formatStr;
is >> formatStr;
int format = 0;
if (formatStr == "32FC3") {
format = CV_32FC3;
} else if (formatStr == "8UC1") {
format = CV_8UC1;
} else {
throw std::runtime_error("Invalid format string.");
}
LOG(INFO) << " Found color stream '" << relativePath <<
"' (" << extension << ", " << formatStr << ").";
video.createColorStream(relativePath, relativePath, extension, format);
}
LOG(INFO) << " Discovering depth streams...";
std::vector<std::string> depthStreams;
std::function<void (const std::string&)> discoverDepthStreams;
discoverDepthStreams = [&](const std::string& path) {
for (auto& entry :
boost::make_iterator_range(fs::directory_iterator(path), {})) {
if (fs::is_directory(entry)) {
LOG(INFO) << " Checking '" << entry.path().string() << "'.";
if (fs::is_directory(entry.path().string() + "/depth")) {
std::string relativePath =
fs::relative(entry.path(), video.path()).string();
depthStreams.push_back(relativePath);
} else {
discoverDepthStreams(entry.path().string());
}
}
}
};
discoverDepthStreams(video.path());
std::sort(depthStreams.begin(), depthStreams.end());
for (int i = 0; i < depthStreams.size(); ++i) {
LOG(INFO) << " Found depth stream '" << depthStreams[i] << "'.";
if (depthStreams[i] == "depth_colmap_dense") {
importColmapDepth(video);
video.createDepthStream(
depthStreams[i], "depth_colmap_dense_imported");
} else if (depthStreams[i] == "depth_colmap_dense_imported") {
// Skip.
} else {
video.createDepthStream(
depthStreams[i], depthStreams[i]);
const std::string posesFile =
video.path() + "/" + depthStreams[i] + "/poses.txt";
if (fs::exists(posesFile)) {
importPoses(video, posesFile, video.numDepthStreams() - 1);
}
}
}
std::vector<std::string> colmapFiles {
video.path() + "/metadata.npz",
video.path() + "/colmap_dense/metadata.npz",
};
for (const std::string& colmapFile : colmapFiles) {
if (fs::is_regular_file(colmapFile)) {
LOG(INFO) <<
" Importing COLMAP reconstruction from '" << colmapFile << "'...";
for (int stream = 0; stream < video.numDepthStreams(); ++stream) {
importColmapRecon(video, colmapFile, stream, false);
}
break;
}
}
const std::string trackFile = video.path() + "/track2d.csv";
if (fs::is_regular_file(trackFile)) {
LOG(INFO) <<
" Importing tracks from '" << trackFile << "'...";
importTracks(video, trackFile);
}
}