Berkeley SfM
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
bsfm::BundleAdjustmentError Struct Reference

#include <cost_functors.h>

Public Member Functions

 BundleAdjustmentError (const Feature &x, const Matrix3d &K)
 
template<typename T >
bool operator() (const T *const rotation, const T *const translation, const T *const point, T *bundle_adjustment_error) const
 

Static Public Member Functions

static ceres::CostFunction * Create (const Feature &x, const Matrix3d &K)
 

Public Attributes

Feature x_
 
Matrix3d K_
 

Detailed Description

Definition at line 118 of file cost_functors.h.

Constructor & Destructor Documentation

bsfm::BundleAdjustmentError::BundleAdjustmentError ( const Feature x,
const Matrix3d &  K 
)
inline

Definition at line 126 of file cost_functors.h.

Member Function Documentation

static ceres::CostFunction* bsfm::BundleAdjustmentError::Create ( const Feature x,
const Matrix3d &  K 
)
inlinestatic

Definition at line 164 of file cost_functors.h.

164  {
165  // 2 residuals: image space u and v coordinates.
166  static const int kNumResiduals = 2;
167 
168  // 3 parameters, axis-angle representation.
169  static const int kNumRotationParameters = 3;
170 
171  // 3 parameters for camera translation.
172  static const int kNumTranslationParameters = 3;
173 
174  // 3 landmark position parameters: world space x, y, z.
175  static const int kNumLandmarkParameters = 3;
176 
177  return new ceres::AutoDiffCostFunction<BundleAdjustmentError,
178  kNumResiduals,
179  kNumRotationParameters,
180  kNumTranslationParameters,
181  kNumLandmarkParameters>(new BundleAdjustmentError(x, K));
182  }
BundleAdjustmentError(const Feature &x, const Matrix3d &K)
template<typename T >
bool bsfm::BundleAdjustmentError::operator() ( const T *const  rotation,
const T *const  translation,
const T *const  point,
T *  bundle_adjustment_error 
) const
inline

Definition at line 129 of file cost_functors.h.

130  {
131  // Normally one would compute x = K * [R | t] X. Instead we have an
132  // axis-angle version of R, and the camera position c. To put the
133  // point X in camera frame, we need to compute R*X+t. Note that t = -R'*c,
134  // so R*X+t = R*(X+R'*t) = R*(X-c). Hence we can first subtract out the given
135  // camera position, and then perform the axis-angle rotation.
136 
137  // Remove camera translation.
138  T origin_point[3];
139  origin_point[0] = point[0] - translation[0];
140  origin_point[1] = point[1] - translation[1];
141  origin_point[2] = point[2] - translation[2];
142 
143  // Rotate point to camera frame.
144  T cam_point[3];
145  ceres::AngleAxisRotatePoint(rotation, origin_point, cam_point);
146 
147  // Get normalized pixel projection.
148  const T& depth = cam_point[2];
149  const T normalized_point[2] = {cam_point[0] / depth, cam_point[1] / depth};
150 
151  // Project normalized point into image using intrinsic parameters.
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);
155 
156  // Error is computed in image space.
157  bundle_adjustment_error[0] = x_.u_ - u;
158  bundle_adjustment_error[1] = x_.v_ - v;
159 
160  return true;
161  }
double v_
Definition: feature.h:62
double u_
Definition: feature.h:62

Member Data Documentation

Matrix3d bsfm::BundleAdjustmentError::K_

Definition at line 125 of file cost_functors.h.

Feature bsfm::BundleAdjustmentError::x_

Definition at line 124 of file cost_functors.h.


The documentation for this struct was generated from the following file: