10 #include <ceres/ceres.h>
11 #include <ceres/rotation.h>
19 template <
typename CameraModel>
23 : observed_x_(point2D(0)), observed_y_(point2D(1)) {}
25 static ceres::CostFunction*
Create(
const Eigen::Vector2d& point2D) {
26 return (
new ceres::AutoDiffCostFunction<
28 CameraModel::kNumParams>(
35 const T*
const point3D,
36 const T*
const camera_params,
40 ceres::UnitQuaternionRotatePoint(qvec, point3D, projection);
41 projection[0] += tvec[0];
42 projection[1] += tvec[1];
43 projection[2] += tvec[2];
46 projection[0] /= projection[2];
47 projection[1] /= projection[2];
50 CameraModel::WorldToImage(camera_params, projection[0], projection[1],
51 &residuals[0], &residuals[1]);
54 residuals[0] -= T(observed_x_);
55 residuals[1] -= T(observed_y_);
61 const double observed_x_;
62 const double observed_y_;
67 template <
typename CameraModel>
71 const Eigen::Vector3d& tvec,
72 const Eigen::Vector2d& point2D)
80 observed_x_(point2D(0)),
81 observed_y_(point2D(1)) {}
83 static ceres::CostFunction*
Create(
const Eigen::Vector4d& qvec,
84 const Eigen::Vector3d& tvec,
85 const Eigen::Vector2d& point2D) {
86 return (
new ceres::AutoDiffCostFunction<
88 CameraModel::kNumParams>(
95 const T*
const camera_params,
97 const T qvec[4] = {T(qw_), T(qx_), T(qy_), T(qz_)};
101 ceres::UnitQuaternionRotatePoint(qvec, point3D, projection);
102 projection[0] += T(tx_);
103 projection[1] += T(ty_);
104 projection[2] += T(tz_);
107 projection[0] /= projection[2];
108 projection[1] /= projection[2];
111 CameraModel::WorldToImage(camera_params, projection[0], projection[1],
112 &residuals[0], &residuals[1]);
115 residuals[0] -= T(observed_x_);
116 residuals[1] -= T(observed_y_);
129 const double observed_x_;
130 const double observed_y_;
139 template <
typename CameraModel>
143 : observed_x_(point2D(0)), observed_y_(point2D(1)) {}
145 static ceres::CostFunction*
Create(
const Eigen::Vector2d& point2D) {
146 return (
new ceres::AutoDiffCostFunction<
148 CameraModel::kNumParams>(
152 template <
typename T>
154 const T*
const rig_tvec,
155 const T*
const rel_qvec,
156 const T*
const rel_tvec,
157 const T*
const point3D,
158 const T*
const camera_params,
159 T* residuals)
const {
162 ceres::QuaternionProduct(rel_qvec, rig_qvec, qvec);
166 ceres::UnitQuaternionRotatePoint(rel_qvec, rig_tvec, tvec);
167 tvec[0] += rel_tvec[0];
168 tvec[1] += rel_tvec[1];
169 tvec[2] += rel_tvec[2];
173 ceres::UnitQuaternionRotatePoint(qvec, point3D, projection);
174 projection[0] += tvec[0];
175 projection[1] += tvec[1];
176 projection[2] += tvec[2];
179 projection[0] /= projection[2];
180 projection[1] /= projection[2];
183 CameraModel::WorldToImage(camera_params, projection[0], projection[1],
184 &residuals[0], &residuals[1]);
187 residuals[0] -= T(observed_x_);
188 residuals[1] -= T(observed_y_);
194 const double observed_x_;
195 const double observed_y_;
208 const Eigen::Vector2d& x2)
209 : x1_(x1(0)), y1_(x1(1)), x2_(x2(0)), y2_(x2(1)) {}
211 static ceres::CostFunction*
Create(
const Eigen::Vector2d& x1,
212 const Eigen::Vector2d& x2) {
218 template <
typename T>
221 T* residuals)
const {
222 Eigen::Matrix<T, 3, 3, Eigen::RowMajor> R;
223 ceres::QuaternionToRotation(qvec, R.data());
226 Eigen::Matrix<T, 3, 3> t_x;
227 t_x << T(0), -tvec[2], tvec[1], tvec[2], T(0), -tvec[0], -tvec[1],
231 const Eigen::Matrix<T, 3, 3> E = t_x * R;
234 const Eigen::Matrix<T, 3, 1> x1_h(T(x1_), T(y1_), T(1));
235 const Eigen::Matrix<T, 3, 1> x2_h(T(x2_), T(y2_), T(1));
238 const Eigen::Matrix<T, 3, 1> Ex1 = E * x1_h;
239 const Eigen::Matrix<T, 3, 1> Etx2 = E.transpose() * x2_h;
240 const T x2tEx1 = x2_h.transpose() * Ex1;
241 residuals[0] = x2tEx1 * x2tEx1 /
242 (Ex1(0) * Ex1(0) + Ex1(1) * Ex1(1) + Etx2(0) * Etx2(0) +
static ceres::CostFunction * Create(const Eigen::Vector4d &qvec, const Eigen::Vector3d &tvec, const Eigen::Vector2d &point2D)
bool operator()(const T *const point3D, const T *const camera_params, T *residuals) const
BundleAdjustmentConstantPoseCostFunction(const Eigen::Vector4d &qvec, const Eigen::Vector3d &tvec, const Eigen::Vector2d &point2D)
BundleAdjustmentCostFunction(const Eigen::Vector2d &point2D)
static ceres::CostFunction * Create(const Eigen::Vector2d &point2D)
bool operator()(const T *const qvec, const T *const tvec, const T *const point3D, const T *const camera_params, T *residuals) const
RelativePoseCostFunction(const Eigen::Vector2d &x1, const Eigen::Vector2d &x2)
static ceres::CostFunction * Create(const Eigen::Vector2d &x1, const Eigen::Vector2d &x2)
bool operator()(const T *const qvec, const T *const tvec, T *residuals) const
bool operator()(const T *const rig_qvec, const T *const rig_tvec, const T *const rel_qvec, const T *const rel_tvec, const T *const point3D, const T *const camera_params, T *residuals) const
static ceres::CostFunction * Create(const Eigen::Vector2d &point2D)
RigBundleAdjustmentCostFunction(const Eigen::Vector2d &point2D)