-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsfm.cc
More file actions
38 lines (33 loc) · 1.23 KB
/
sfm.cc
File metadata and controls
38 lines (33 loc) · 1.23 KB
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
#include "sfm.h"
#include <google/protobuf/text_format.h>
#include <filesystem>
#include "glog/logging.h"
#include <fstream>
namespace sfm {
absl::StatusOr<std::vector<std::string>> GetFilesFromDirectory(
absl::string_view dir) {
std::vector<std::string> files;
if (!std::filesystem::exists(dir) || !std::filesystem::is_directory(dir)) {
return absl::InvalidArgumentError(absl::StrFormat(
"Directory '%s' does not exist or is not a directory.", dir));
}
for (const auto& entry : std::filesystem::directory_iterator(dir)) {
if (entry.is_regular_file() && entry.path().extension() == ".jpg") {
files.push_back(entry.path().string());
}
}
return files;
}
absl::StatusOr<proto::CameraMatrix> LoadCameraMatrixFromTextProtoFile(
absl::string_view file_path) {
std::ifstream file(file_path.data());
std::string text_proto((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());
proto::CalibrationResult message;
if (!google::protobuf::TextFormat::ParseFromString(text_proto.data(),
&message)) {
return absl::InternalError("Failed to parse proto message");
}
return message.camera_matrix();
}
} // namespace sfm