Skip to content

Commit 86d2500

Browse files
authored
Merge pull request #169 from MotivaCG/feature-colmap-image-path
Allow overriding input image path when using COLMAP
2 parents ff463b7 + 5400876 commit 86d2500

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

colmap.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using namespace torch::indexing;
88

99
namespace cm{
1010

11-
InputData inputDataFromColmap(const std::string &projectRoot){
11+
InputData inputDataFromColmap(const std::string &projectRoot, const std::string& colmapImageSourcePath){
1212
InputData ret;
1313
fs::path cmRoot(projectRoot);
1414

@@ -112,8 +112,10 @@ InputData inputDataFromColmap(const std::string &projectRoot){
112112
filePath += ch;
113113
}
114114

115-
// TODO: should "images" be an option?
116-
cam.filePath = (fs::path(projectRoot) / "images" / filePath).string();
115+
if (colmapImageSourcePath.empty())
116+
cam.filePath = (fs::path(projectRoot) / "images" / filePath).string();
117+
else
118+
cam.filePath = (fs::path(colmapImageSourcePath) / filePath).string();
117119

118120
unorientedPoses[i].index_put_({Slice(None, 3), Slice(None, 3)}, Rinv);
119121
unorientedPoses[i].index_put_({Slice(None, 3), Slice(3, 4)}, Tinv);

colmap.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "input_data.hpp"
66

77
namespace cm{
8-
InputData inputDataFromColmap(const std::string &projectRoot);
8+
InputData inputDataFromColmap(const std::string &projectRoot, const std::string& colmapImageSourcePath = "");
99

1010
enum CameraModel{
1111
SimplePinhole = 0, Pinhole, SimpleRadial, Radial,

input_data.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ using namespace torch::indexing;
88
using json = nlohmann::json;
99

1010
namespace ns{ InputData inputDataFromNerfStudio(const std::string &projectRoot); }
11-
namespace cm{ InputData inputDataFromColmap(const std::string &projectRoot); }
11+
namespace cm{ InputData inputDataFromColmap(const std::string &projectRoot, const std::string& imageSourcePath); }
1212
namespace osfm { InputData inputDataFromOpenSfM(const std::string &projectRoot); }
1313
namespace omvg { InputData inputDataFromOpenMVG(const std::string &projectRoot); }
1414

15-
InputData inputDataFromX(const std::string &projectRoot){
15+
InputData inputDataFromX(const std::string &projectRoot, const std::string& colmapImageSourcePath){
1616
fs::path root(projectRoot);
1717

1818
if (fs::exists(root / "transforms.json")){
1919
return ns::inputDataFromNerfStudio(projectRoot);
2020
}else if (fs::exists(root / "sparse") || fs::exists(root / "cameras.bin")){
21-
return cm::inputDataFromColmap(projectRoot);
21+
return cm::inputDataFromColmap(projectRoot, colmapImageSourcePath);
2222
}else if (fs::exists(root / "reconstruction.json")){
2323
return osfm::inputDataFromOpenSfM(projectRoot);
2424
}else if (fs::exists(root / "opensfm" / "reconstruction.json")){

input_data.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct InputData{
5959

6060
void saveCameras(const std::string &filename, bool keepCrs);
6161
};
62-
InputData inputDataFromX(const std::string &projectRoot);
62+
// The colmapImageSourcePath is only used in Colmap. In other methods, this path is ignored.
63+
InputData inputDataFromX(const std::string& projectRoot, const std::string& colmapImageSourcePath = "");
6364

6465
#endif

opensplat.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ int main(int argc, char *argv[]){
4141
("densify-size-thresh", "Gaussians' scales below this threshold are duplicated, otherwise split", cxxopts::value<float>()->default_value("0.01"))
4242
("stop-screen-size-at", "Stop splitting gaussians that are larger than [split-screen-size] after these many steps", cxxopts::value<int>()->default_value("4000"))
4343
("split-screen-size", "Split gaussians that are larger than this percentage of screen space", cxxopts::value<float>()->default_value("0.05"))
44+
("colmap-image-path", "Override the default image path for COLMAP-based input", cxxopts::value<std::string>()->default_value(""))
4445

4546
("h,help", "Print usage")
4647
("version", "Print version")
@@ -90,6 +91,7 @@ int main(int argc, char *argv[]){
9091
const float densifySizeThresh = result["densify-size-thresh"].as<float>();
9192
const int stopScreenSizeAt = result["stop-screen-size-at"].as<int>();
9293
const float splitScreenSize = result["split-screen-size"].as<float>();
94+
const std::string colmapImageSourcePath = result["colmap-image-path"].as<std::string>();
9395

9496
torch::Device device = torch::kCPU;
9597
int displayStep = 10;
@@ -111,7 +113,7 @@ int main(int argc, char *argv[]){
111113
#endif
112114

113115
try{
114-
InputData inputData = inputDataFromX(projectRoot);
116+
InputData inputData = inputDataFromX(projectRoot, colmapImageSourcePath);
115117

116118
parallel_for(inputData.cameras.begin(), inputData.cameras.end(), [&downScaleFactor](Camera &cam){
117119
cam.loadImage(downScaleFactor);

0 commit comments

Comments
 (0)