[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/NewChromantics/OpenSplat/OpenSplatLibrary/input_data.cpp [Back]  [Original]

#include 
#include 
#include "input_data.hpp"
#include "cv_utils.hpp"
#include "trainer.hpp"	//	NoCameraException
#include "nerfstudio.hpp"

namespace fs = std::filesystem;
using namespace torch::indexing;
using json = nlohmann::json;

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,bool CenterAndNormalisePoints,bool AddCameras)
{
    fs::path root(projectRoot);

    if (fs::exists(root / "transforms.json")){
        return ns::inputDataFromNerfStudio(projectRoot,CenterAndNormalisePoints,AddCameras);
    }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)");
    }
}

Camera::Camera(CameraIntrinsics intrinsics,const torch::Tensor &camToWorld,std::filesystem::path cameraImageFilename) : 
	intrinsics(intrinsics),
	camToWorld(camToWorld), 
	cameraImagePath(cameraImageFilename)
{
}

void CameraIntrinsics::RemoveDistortionParameters()
{
	k1 = 0;
	k2 = 0;
	k3 = 0;
	p1 = 0;
	p2 = 0;
}

void CameraIntrinsics::ScaleTo(int Width,int Height)
{
	//	allowing x & y scale is going to mess up distortion parameters
	//	this would be fine for forward rendering (which doesnt distort)
	//	if there are distortion values here for record of the original camera
	//	they should really have been zeroed out already if they no longer apply
	//	to the image they're attached to
	if ( HasDistortionParameters() )
		throw std::runtime_error("Cannot scale CameraIntrinsics which have distortion parameters");
	
	if ( Width 

Web Proxy Viewer  |  New URL  |  Original Page