33#include "ceres/ceres.h"
39class EuclideanIntersectCostFunctor {
41 EuclideanIntersectCostFunctor(
const Marker& marker,
42 const EuclideanCamera&
camera)
43 : marker_(marker), camera_(
camera) {}
47 typedef Eigen::Matrix<T, 3, 3>
Mat3;
48 typedef Eigen::Matrix<T, 3, 1>
Vec3;
51 Mat3 R(camera_.R.cast<
T>());
52 Vec3 t(camera_.t.cast<
T>());
54 Vec3 projected =
R *
x + t;
55 projected /= projected(2);
57 residuals[0] = (projected(0) -
T(marker_.x)) * marker_.weight;
58 residuals[1] = (projected(1) -
T(marker_.y)) * marker_.weight;
63 const Marker& marker_;
64 const EuclideanCamera& camera_;
71 if (markers.size() < 2) {
77 Mat3 K = Mat3::Identity();
80 for (
int i = 0; i < markers.size(); ++i) {
87 Mat2X points(2, markers.size());
88 for (
int i = 0; i < markers.size(); ++i) {
89 points(0, i) = markers[i].x;
90 points(1, i) = markers[i].y;
94 LG <<
"Intersecting with " << markers.size() <<
" markers.";
99 Vec3 X = Xp.head<3>();
101 ceres::Problem problem;
104 int num_residuals = 0;
105 for (
int i = 0; i < markers.size(); ++i) {
106 const Marker& marker = markers[i];
107 if (marker.
weight != 0.0) {
111 problem.AddResidualBlock(
112 new ceres::AutoDiffCostFunction<EuclideanIntersectCostFunctor,
115 new EuclideanIntersectCostFunctor(marker,
camera)),
125 LG <<
"Number of residuals: " << num_residuals;
126 if (!num_residuals) {
127 LG <<
"Skipping running minimizer with zero residuals";
140 ceres::Solver::Options solver_options;
141 solver_options.linear_solver_type = ceres::DENSE_QR;
142 solver_options.max_num_iterations = 50;
143 solver_options.update_state_every_iteration =
true;
144 solver_options.parameter_tolerance = 1
e-16;
145 solver_options.function_tolerance = 1
e-16;
148 ceres::Solver::Summary summary;
149 ceres::Solve(solver_options, &problem, &summary);
151 VLOG(1) <<
"Summary:\n" << summary.FullReport();
154 for (
int i = 0; i < cameras.size(); ++i) {
159 LOG(ERROR) <<
"POINT BEHIND CAMERA " << markers[i].image <<
": "
174struct ProjectiveIntersectCostFunction {
176 typedef Vec FMatrixType;
177 typedef Vec4 XMatrixType;
179 ProjectiveIntersectCostFunction(
181 const ProjectiveReconstruction& reconstruction)
182 : markers(markers), reconstruction(reconstruction) {}
185 Vec residuals(2 * markers.size());
187 for (
int i = 0; i < markers.size(); ++i) {
188 const ProjectiveCamera&
camera =
189 *reconstruction.CameraForImage(markers[i].
image);
191 projected /= projected(2);
192 residuals[2 * i + 0] = projected(0) - markers[i].x;
193 residuals[2 * i + 1] = projected(1) - markers[i].y;
198 const ProjectiveReconstruction& reconstruction;
205 if (markers.size() < 2) {
211 for (
int i = 0; i < markers.size(); ++i) {
213 cameras.push_back(
camera->P);
217 Mat2X points(2, markers.size());
218 for (
int i = 0; i < markers.size(); ++i) {
219 points(0, i) = markers[i].x;
220 points(1, i) = markers[i].y;
224 LG <<
"Intersecting with " << markers.size() <<
" markers.";
230 ProjectiveIntersectCostFunction triangulate_cost(markers, *reconstruction);
231 Solver::SolverParameters
params;
232 Solver solver(triangulate_cost);
234 Solver::Results results = solver.minimize(
params, &
X);
238 for (
int i = 0; i < cameras.size(); ++i) {
243 LOG(ERROR) <<
"POINT BEHIND CAMERA " << markers[i].image <<
": "
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between camera
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a point
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
void InsertPoint(int track, const Vec3 &X)
EuclideanCamera * CameraForImage(int image)
Returns a pointer to the camera corresponding to image.
void InsertPoint(int track, const Vec4 &X)
ProjectiveCamera * CameraForImage(int image)
Returns a pointer to the camera corresponding to image.
input_tx image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, "preview_img") .compute_source("compositor_compute_preview.glsl") .do_static_compilation(true)
Eigen::Matrix< double, 3, 3 > Mat3
bool EuclideanIntersect(const vector< Marker > &markers, EuclideanReconstruction *reconstruction)
Eigen::Matrix< double, 3, 4 > Mat34
std::vector< ElementType, Eigen::aligned_allocator< ElementType > > vector
Eigen::Matrix< double, 2, Eigen::Dynamic > Mat2X
bool ProjectiveIntersect(const vector< Marker > &markers, ProjectiveReconstruction *reconstruction)
void P_From_KRt(const Mat3 &K, const Mat3 &R, const Vec3 &t, Mat34 *P)
void NViewTriangulateAlgebraic(const Matrix< T, 2, Dynamic > &x, const vector< Matrix< T, 3, 4 > > &Ps, Matrix< T, 4, 1 > *X)