diff --git a/docs/bundleadjustment.tex b/docs/bundleadjustment.tex index 1f633616a..ac260a0ec 100644 --- a/docs/bundleadjustment.tex +++ b/docs/bundleadjustment.tex @@ -37,9 +37,8 @@ struct SnavelyReprojectionError { // 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 @@ struct SnavelyReprojectionError { 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 @@ ceres::Solve(options, &problem, &summary); 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 850690eab..cc6f04adf 100644 --- a/examples/simple_bundle_adjuster.cc +++ b/examples/simple_bundle_adjuster.cc @@ -139,9 +139,8 @@ struct SnavelyReprojectionError { // 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 @@ struct SnavelyReprojectionError { 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 eaf412920..070421789 100644 --- a/examples/snavely_reprojection_error.h +++ b/examples/snavely_reprojection_error.h @@ -71,8 +71,8 @@ struct SnavelyReprojectionError { // 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 @@ struct SnavelyReprojectionError { 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 @@ struct SnavelyReprojectionErrorWithQuaternions { // 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);