Correct snavely reprojection error in code and doc.
The snavely reprojection error is wrong both in the sample code and
in the documentation. It should not multiply by the focal length
before calculating the distortion.
Change-Id: I292af962e634506a7cc57af9ce72b08f81ce3425
diff --git a/docs/bundleadjustment.tex b/docs/bundleadjustment.tex
index 1f63361..ac260a0 100644
--- a/docs/bundleadjustment.tex
+++ b/docs/bundleadjustment.tex
@@ -37,9 +37,8 @@
// Compute the center of distortion. The sign change comes from
// the camera model that Noah Snavely's Bundler assumes, whereby
// the camera coordinate system has a negative z axis.
- const T& focal = camera[6];
- T xp = - focal * p[0] / p[2];
- T yp = - focal * p[1] / p[2];
+ T xp = - p[0] / p[2];
+ T yp = - p[1] / p[2];
// Apply second and fourth order radial distortion.
const T& l1 = camera[7];
@@ -48,8 +47,9 @@
T distortion = T(1.0) + r2 * (l1 + l2 * r2);
// Compute final projected point position.
- T predicted_x = distortion * xp;
- T predicted_y = distortion * yp;
+ const T& focal = camera[6];
+ T predicted_x = focal * distortion * xp;
+ T predicted_y = focal * distortion * yp;
// The error is the difference between the predicted and observed position.
residuals[0] = predicted_x - T(observed_x);
@@ -98,4 +98,5 @@
std::cout << summary.FullReport() << "\n";
\end{minted}
-For a more sophisticated bundle adjustment example which demonstrates the use of Ceres' more advanced features including its various linear solvers, robust loss functions and local parameterizations see \texttt{examples/bundle\_adjuster.cc}.
\ No newline at end of file
+For a more sophisticated bundle adjustment example which demonstrates the use of Ceres' more advanced features including its various linear solvers, robust loss functions and local parameterizations see \texttt{examples/bundle\_adjuster.cc}.
+
diff --git a/examples/simple_bundle_adjuster.cc b/examples/simple_bundle_adjuster.cc
index 850690e..cc6f04a 100644
--- a/examples/simple_bundle_adjuster.cc
+++ b/examples/simple_bundle_adjuster.cc
@@ -139,9 +139,8 @@
// Compute the center of distortion. The sign change comes from
// the camera model that Noah Snavely's Bundler assumes, whereby
// the camera coordinate system has a negative z axis.
- const T& focal = camera[6];
- T xp = - focal * p[0] / p[2];
- T yp = - focal * p[1] / p[2];
+ T xp = - p[0] / p[2];
+ T yp = - p[1] / p[2];
// Apply second and fourth order radial distortion.
const T& l1 = camera[7];
@@ -150,8 +149,9 @@
T distortion = T(1.0) + r2 * (l1 + l2 * r2);
// Compute final projected point position.
- T predicted_x = distortion * xp;
- T predicted_y = distortion * yp;
+ const T& focal = camera[6];
+ T predicted_x = focal * distortion * xp;
+ T predicted_y = focal * distortion * yp;
// The error is the difference between the predicted and observed position.
residuals[0] = predicted_x - T(observed_x);
diff --git a/examples/snavely_reprojection_error.h b/examples/snavely_reprojection_error.h
index eaf4129..0704217 100644
--- a/examples/snavely_reprojection_error.h
+++ b/examples/snavely_reprojection_error.h
@@ -71,8 +71,8 @@
// the camera model that Noah Snavely's Bundler assumes, whereby
// the camera coordinate system has a negative z axis.
const T& focal = camera[6];
- T xp = - focal * p[0] / p[2];
- T yp = - focal * p[1] / p[2];
+ T xp = - p[0] / p[2];
+ T yp = - p[1] / p[2];
// Apply second and fourth order radial distortion.
const T& l1 = camera[7];
@@ -81,8 +81,8 @@
T distortion = T(1.0) + r2 * (l1 + l2 * r2);
// Compute final projected point position.
- T predicted_x = distortion * xp;
- T predicted_y = distortion * yp;
+ T predicted_x = focal * distortion * xp;
+ T predicted_y = focal * distortion * yp;
// The error is the difference between the predicted and observed position.
residuals[0] = predicted_x - T(observed_x);
@@ -128,16 +128,16 @@
// Compute the center of distortion. The sign change comes from
// the camera model that Noah Snavely's Bundler assumes, whereby
// the camera coordinate system has a negative z axis.
- T xp = - focal * p[0] / p[2];
- T yp = - focal * p[1] / p[2];
+ T xp = - p[0] / p[2];
+ T yp = - p[1] / p[2];
// Apply second and fourth order radial distortion.
T r2 = xp*xp + yp*yp;
T distortion = T(1.0) + r2 * (l1 + l2 * r2);
// Compute final projected point position.
- T predicted_x = distortion * xp;
- T predicted_y = distortion * yp;
+ T predicted_x = focal * distortion * xp;
+ T predicted_y = focal * distortion * yp;
// The error is the difference between the predicted and observed position.
residuals[0] = predicted_x - T(observed_x);