// adding error function
struct TranslationOffsetError {
TranslationOffsetError(double t_x, double t_y, double t_z)
: t_x(t_x), t_y(t_y), t_z(t_z) {}
template <typename T>
bool operator()(const T* const cameraRT,
T* offset) const {
offset[0] = t_x - cameraRT[3]; // cameraRT[0..2] is the rotational part
offset[1] = t_y - cameraRT[4];
offset[2] = t_z - cameraRT[5];
}
double t_x;
double t_y;
double t_z;
};
...
//somewhere in main add residual block:
...
for (int c = 0; c < bal_problem->num_cameras(); c++)
{
ceres::CostFunction* cost_function =
new ceres::AutoDiffCostFunction<TranslationOffsetError, 3, 6>(
new TranslationOffsetError(bal_problem->cameralocation(c)[0],bal_problem->cameralocation(c)[1],bal_problem->cameralocation(c)[2]));
problem.AddResidualBlock(cost_function,
NULL, // squared loss,
bal_problem->mutable_cameraRT_for_observation(c));
}
...
Error in evaluating the ResidualBlock.
There are two possible reasons. Either the CostFunction did not evaluate and fill all
residual and jacobians that were requested or there was a non-finite value (nan/infinite)
generated during the or jacobian computation.
Residual Block size: 1 parameter blocks x 3 residuals
For each parameter block, the value of the parameters are printed in the first column
and the value of the jacobian under the corresponding residual. If a ParameterBlock was
held constant then the corresponding jacobian is printed as 'Not Computed'. If an entry
of the Jacobian/residual array was requested but was not written to by user code, it is
indicated by 'Uninitialized'. This is an error. Residuals or Jacobian values evaluating
to Inf or NaN is also an error.
Residuals: 0 0 0
Parameter Block 0, size: 6
0 | Not Computed Not Computed Not Computed
0 | Not Computed Not Computed Not Computed
0 | Not Computed Not Computed Not Computed
0 | Not Computed Not Computed Not Computed
0 | Not Computed Not Computed Not Computed
0 | Not Computed Not Computed Not Computed The residual is missing a return true.
--
--
----------------------------------------
Ceres Solver Google Group
http://groups.google.com/group/ceres-solver?hl=en?hl=en