#include
#include
#include "input_data.hpp"
#include "cv_utils.hpp"
namespace fs = std::filesystem;
using namespace torch::indexing;
using json = nlohmann::json;
namespace ns{ InputData inputDataFromNerfStudio(const std::string &projectRoot); }
namespace cm{ InputData inputDataFromColmap(const std::string &projectRoot, const std::string& imageSourcePath); }
namespace osfm { InputData inputDataFromOpenSfM(const std::string &projectRoot); }
namespace omvg { InputData inputDataFromOpenMVG(const std::string &projectRoot); }
InputData inputDataFromX(const std::string &projectRoot, const std::string& colmapImageSourcePath){
fs::path root(projectRoot);
if (fs::exists(root / "transforms.json")){
return ns::inputDataFromNerfStudio(projectRoot);
}else if (fs::exists(root / "sparse") || fs::exists(root / "cameras.bin")){
return cm::inputDataFromColmap(projectRoot, colmapImageSourcePath);
}else if (fs::exists(root / "reconstruction.json")){
return osfm::inputDataFromOpenSfM(projectRoot);
}else if (fs::exists(root / "opensfm" / "reconstruction.json")){
return osfm::inputDataFromOpenSfM((root / "opensfm").string());
}else if (fs::exists(root / "sfm_data.json")){
return omvg::inputDataFromOpenMVG((root).string());
}
else{
throw std::runtime_error("Invalid project folder (must be either a colmap or nerfstudio or openmvg project folder)");
}
}
torch::Tensor Camera::getIntrinsicsMatrix(){
return torch::tensor({{fx, 0.0f, cx},
{0.0f, fy, cy},
{0.0f, 0.0f, 1.0f}}, torch::kFloat32);
}
void Camera::loadImage(float downscaleFactor){
// Populates image and K, then updates the camera parameters
// Caution: this function has destructive behaviors
// and should be called only once
if (image.numel()) std::runtime_error("loadImage already called");
std::cout