123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- struct CostFunctor {
- bool operator()(const double* const x, double* residual) const {
- residual[0] = 10.0 - x[0];
- return true;
- }
- };
- int main(int argc, char** argv) {
- google::InitGoogleLogging(argv[0]);
-
-
- double x = 0.5;
- const double initial_x = x;
-
- ceres::Problem problem;
-
-
- ceres::CostFunction* cost_function =
- new ceres::NumericDiffCostFunction<CostFunctor, ceres::CENTRAL, 1, 1>(
- new CostFunctor);
- problem.AddResidualBlock(cost_function, nullptr, &x);
-
- ceres::Solver::Options options;
- options.minimizer_progress_to_stdout = true;
- ceres::Solver::Summary summary;
- ceres::Solve(options, &problem, &summary);
- std::cout << summary.BriefReport() << "\n";
- std::cout << "x : " << initial_x << " -> " << x << "\n";
- return 0;
- }
|