forked from pierotofy/OpenSplat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nerfstudio.hpp
104 lines (86 loc) · 2.91 KB
/
nerfstudio.hpp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#ifndef NERFSTUDIO_H
#define NERFSTUDIO_H
#include <iostream>
#include <string>
#include <fstream>
#include <unordered_map>
#include <torch/torch.h>
#include <opencv2/calib3d.hpp>
#include "vendor/json/json_fwd.hpp"
using json = nlohmann::json;
namespace ns{
typedef std::vector<std::vector<float>> Mat4;
struct Frame{
std::string filePath = "";
int width = 0;
int height = 0;
double fx = 0;
double fy = 0;
double cx = 0;
double cy = 0;
double k1 = 0;
double k2 = 0;
double p1 = 0;
double p2 = 0;
double k3 = 0;
Mat4 transformMatrix;
};
void to_json(json &j, const Frame &f);
void from_json(const json& j, Frame &f);
struct Transforms{
std::string cameraModel;
std::vector<Frame> frames;
std::string plyFilePath;
};
void to_json(json &j, const Transforms &t);
void from_json(const json& j, Transforms &t);
enum CameraType { Perspective };
struct Camera{
int width = 0;
int height = 0;
float fx = 0;
float fy = 0;
float cx = 0;
float cy = 0;
float k1 = 0;
float k2 = 0;
float k3 = 0;
float p1 = 0;
float p2 = 0;
torch::Tensor camToWorld;
std::string filePath = "";
CameraType cameraType = CameraType::Perspective;
Camera(int width, int height, float fx, float fy, float cx, float cy,
float k1, float k2, float k3, float p1, float p2,
const torch::Tensor &camToWorld, const std::string &filePath) :
width(width), height(height), fx(fx), fy(fy), cx(cx), cy(cy),
k1(k1), k2(k2), k3(k3), p1(p1), p2(p2),
camToWorld(camToWorld), filePath(filePath) {}
torch::Tensor getIntrinsicsMatrix();
bool hasDistortionParameters();
std::vector<float> undistortionParameters();
void scaleOutputResolution(float scaleFactor);
torch::Tensor getImage(int downscaleFactor);
void loadImage(float downscaleFactor);
torch::Tensor K;
torch::Tensor image;
std::unordered_map<int, torch::Tensor> imagePyramids;
};
Transforms readTransforms(const std::string &filename);
torch::Tensor posesFromTransforms(const Transforms &t);
std::tuple<torch::Tensor, torch::Tensor> autoOrientAndCenterPoses(const torch::Tensor &poses);
torch::Tensor rotationMatrix(const torch::Tensor &a, const torch::Tensor &b);
struct Points{
torch::Tensor xyz;
torch::Tensor rgb;
};
struct InputData{
std::vector<Camera> cameras;
float scaleFactor;
torch::Tensor transformMatrix;
Points points;
std::tuple<std::vector<Camera>, Camera *> getCameras(bool validate, const std::string &valImage = "random");
};
InputData inputDataFromNerfStudio(const std::string &projectRoot);
}
#endif