aboutsummaryrefslogtreecommitdiff
path: root/examples/simple_bundle_adjuster.cc
diff options
context:
space:
mode:
authorSascha Haeberling <haeberling@google.com>2013-07-23 19:00:21 -0700
committerSascha Haeberling <haeberling@google.com>2013-07-24 12:00:09 -0700
commit1d2624a10e2c559f8ba9ef89eaa30832c0a83a96 (patch)
treef43667ef858dd0f377b15a58a9d5c9a126762c55 /examples/simple_bundle_adjuster.cc
parent0ae28bd5885b5daa526898fcf7c323dc2c3e1963 (diff)
downloadceres-solver-1d2624a10e2c559f8ba9ef89eaa30832c0a83a96.tar.gz
Update ceres to the latest version in google3.
Change-Id: I0165fffa55f60714f23e0096eac89fa68df75a05
Diffstat (limited to 'examples/simple_bundle_adjuster.cc')
-rw-r--r--examples/simple_bundle_adjuster.cc18
1 files changed, 13 insertions, 5 deletions
diff --git a/examples/simple_bundle_adjuster.cc b/examples/simple_bundle_adjuster.cc
index cc6f04a..736d4a2 100644
--- a/examples/simple_bundle_adjuster.cc
+++ b/examples/simple_bundle_adjuster.cc
@@ -160,6 +160,14 @@ struct SnavelyReprojectionError {
return true;
}
+ // Factory to hide the construction of the CostFunction object from
+ // the client code.
+ static ceres::CostFunction* Create(const double observed_x,
+ const double observed_y) {
+ return (new ceres::AutoDiffCostFunction<SnavelyReprojectionError, 2, 9, 3>(
+ new SnavelyReprojectionError(observed_x, observed_y)));
+ }
+
double observed_x;
double observed_y;
};
@@ -177,6 +185,8 @@ int main(int argc, char** argv) {
return 1;
}
+ const double* observations = bal_problem.observations();
+
// Create residuals for each observation in the bundle adjustment problem. The
// parameters for cameras and points are added automatically.
ceres::Problem problem;
@@ -184,12 +194,10 @@ int main(int argc, char** argv) {
// Each Residual block takes a point and a camera as input and outputs a 2
// dimensional residual. Internally, the cost function stores the observed
// image location and compares the reprojection against the observation.
- ceres::CostFunction* cost_function =
- new ceres::AutoDiffCostFunction<SnavelyReprojectionError, 2, 9, 3>(
- new SnavelyReprojectionError(
- bal_problem.observations()[2 * i + 0],
- bal_problem.observations()[2 * i + 1]));
+ ceres::CostFunction* cost_function =
+ SnavelyReprojectionError::Create(observations[2 * i + 0],
+ observations[2 * i + 1]);
problem.AddResidualBlock(cost_function,
NULL /* squared loss */,
bal_problem.mutable_camera_for_observation(i),