33#include "ceres/ceres.h"
39class EuclideanIntersectCostFunctor {
41 EuclideanIntersectCostFunctor(
const Marker& marker,
42 const EuclideanCamera& camera)
47 typedef Eigen::Matrix<T, 3, 3>
Mat3;
48 typedef Eigen::Matrix<T, 3, 1>
Vec3;
54 Vec3 projected =
R * x + t;
55 projected /= projected(2);
77 Mat3 K = Mat3::Identity();
80 for (
int i = 0; i <
markers.size(); ++i) {
88 for (
int i = 0; i <
markers.size(); ++i) {
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) {
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";
133 Vec3 point =
X.head<3>();
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) {
157 Vec3 x = camera.R *
X + camera.t;
165 Vec3 point =
X.head<3>();
174struct ProjectiveIntersectCostFunction {
176 typedef Vec FMatrixType;
177 typedef Vec4 XMatrixType;
179 ProjectiveIntersectCostFunction(
181 const ProjectiveReconstruction& reconstruction)
187 for (
int i = 0; i <
markers.size(); ++i) {
188 const ProjectiveCamera& camera =
190 Vec3 projected = camera.P *
X;
191 projected /= projected(2);
192 residuals[2 * i + 0] = projected(0) -
markers[i].x;
193 residuals[2 * i + 1] = projected(1) -
markers[i].y;
211 for (
int i = 0; i <
markers.size(); ++i) {
213 cameras.push_back(camera->P);
218 for (
int i = 0; i <
markers.size(); ++i) {
224 LG <<
"Intersecting with " <<
markers.size() <<
" markers.";
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 <<
": "
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
void InsertPoint(int track, const Vec4 &X)
ProjectiveCamera * CameraForImage(int image)
Returns a pointer to the camera corresponding to image.
const vector< Marker > & markers
const ProjectiveReconstruction & reconstruction
const EuclideanCamera & camera_
Eigen::Matrix< double, 3, 3 > Mat3
bool EuclideanIntersect(const vector< Marker > &markers, EuclideanReconstruction *reconstruction)
Eigen::Matrix< double, 3, 4 > Mat34
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)