53 #ifndef BSFM_OPTIMIZATION_COST_FUNCTORS_H
54 #define BSFM_OPTIMIZATION_COST_FUNCTORS_H
56 #include <ceres/rotation.h>
58 #include <glog/logging.h>
60 #include "../geometry/point_3d.h"
61 #include "../matching/feature.h"
82 bool operator()(
const T*
const P, T* geometric_error)
const {
86 T scale = P[2] * X_.
X() + P[5] * X_.
Y() + P[8] * X_.
Z() + P[11];
88 x_.
u_ - (P[0] * X_.
X() + P[3] * X_.
Y() + P[6] * X_.
Z() + P[9]) / scale;
90 x_.
v_ - (P[1] * X_.
X() + P[4] * X_.
Y() + P[7] * X_.
Z() + P[10]) / scale;
97 static const int kNumResiduals = 2;
98 static const int kNumCameraParameters = 12;
128 template <
typename T>
129 bool operator()(
const T*
const rotation,
const T*
const translation,
130 const T*
const point, T* bundle_adjustment_error)
const {
139 origin_point[0] = point[0] - translation[0];
140 origin_point[1] = point[1] - translation[1];
141 origin_point[2] = point[2] - translation[2];
145 ceres::AngleAxisRotatePoint(rotation, origin_point, cam_point);
148 const T& depth = cam_point[2];
149 const T normalized_point[2] = {cam_point[0] / depth, cam_point[1] / depth};
152 const T u =
K_(0, 0) * normalized_point[0] +
153 K_(0, 1) * normalized_point[1] +
K_(0, 2);
154 const T v =
K_(1, 1) * normalized_point[1] +
K_(1, 2);
157 bundle_adjustment_error[0] = x_.
u_ - u;
158 bundle_adjustment_error[1] = x_.
v_ - v;
166 static const int kNumResiduals = 2;
169 static const int kNumRotationParameters = 3;
172 static const int kNumTranslationParameters = 3;
175 static const int kNumLandmarkParameters = 3;
179 kNumRotationParameters,
180 kNumTranslationParameters,
BundleAdjustmentError(const Feature &x, const Matrix3d &K)
bool operator()(const T *const rotation, const T *const translation, const T *const point, T *bundle_adjustment_error) const
GeometricError(const Feature &x, const Point3D &X)
static ceres::CostFunction * Create(const Feature &x, const Matrix3d &K)
static ceres::CostFunction * Create(const Feature &x, const Point3D &X)
bool operator()(const T *const P, T *geometric_error) const