How to Use Ceres-Solver in a New Project (Visual Studio 2015)

1,163 views
Skip to first unread message

sink...@gmail.com

unread,
Mar 14, 2016, 3:12:43 PM3/14/16
to Ceres Solver
Hello. I have successfully built the Ceres solution in Visual Studio 2015. IOW, I have built a Release version (32-bit) as shown below. The Run_Test runs successfully, and I can create a .exe file from any of the test programs and run it successfully.

My problem is this. I don't know what to do next. I want to use Ceres in a new C++ project in Visual Studio, but I don't know how to integrate these newly-created build files in my new project. I'm imagining that CMake will be involved.

Can anyone help me with specific next steps? I just don't have the C++/Visual Studio/Cmake experience/knowledge. Thankfully, I understand non-linear modeling better than I do C++!! :)

Any help is *very* appreciated.

I know that the ceres-solver.org page discusses how to install and use, but the directions aren't clear enough given my knowledge.

Tom

92>------ Rebuild All started: Project: INSTALL, Configuration: Release Win32 ------
92>  -- Install configuration: "Release"
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/autodiff_cost_function.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/autodiff_local_parameterization.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/ceres.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/conditioned_cost_function.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/cost_function.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/cost_function_to_functor.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/covariance.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/crs_matrix.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/cubic_interpolation.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/c_api.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/dynamic_autodiff_cost_function.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/dynamic_cost_function_to_functor.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/dynamic_numeric_diff_cost_function.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/fpclassify.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/gradient_checker.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/gradient_problem.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/gradient_problem_solver.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/iteration_callback.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/jet.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/local_parameterization.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/loss_function.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/normal_prior.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/numeric_diff_cost_function.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/numeric_diff_options.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/ordered_groups.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/problem.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/rotation.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/sized_cost_function.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/solver.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/types.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/version.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/internal/autodiff.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/internal/disable_warnings.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/internal/eigen.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/internal/fixed_array.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/internal/macros.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/internal/manual_constructor.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/internal/numeric_diff.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/internal/port.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/internal/reenable_warnings.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/internal/scoped_ptr.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/internal/variadic_evaluate.h
92>  -- Installing: C:/Program Files (x86)/Ceres/include/ceres/internal/config.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/include/ceres/internal/miniglog/glog/logging.h
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/CMake/CeresTargets.cmake
92>  -- Installing: C:/Program Files (x86)/Ceres/CMake/CeresTargets-release.cmake
92>  -- Installing: C:/Program Files (x86)/Ceres/CMake/CeresConfig.cmake
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/CMake/CeresConfigVersion.cmake
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/CMake/FindEigen.cmake
92>  -- Up-to-date: C:/Program Files (x86)/Ceres/CMake/FindGlog.cmake
92>  -- Installing: C:/Program Files (x86)/Ceres/lib/ceres.lib
========== Rebuild All: 92 succeeded, 0 failed, 0 skipped ==========

sink...@gmail.com

unread,
Mar 15, 2016, 12:21:15 PM3/15/16
to Ceres Solver
 
Here are the steps I used to integrate the Ceres capabilities into a new project in Visual Studio 2015...:

A. Create a new directory for the project, e.g. c:\myPrj

B. Add two files to this directory:
1.  CMakeLists.txt (Use the example CMakeLists.txt code from the ceres-solver.org Build and Install Section/Using Ceres with CMake)
Make sure that the program specified in the CMakeLists.txt is the .cc program you include in the directory.
------------------------------------------------------------------------
cmake_minimum_required(VERSION 2.8)
project(helloworld)

find_package(Ceres REQUIRED)
include_directories(${CERES_INCLUDE_DIRS})

# helloworld
add_executable(helloworld helloworld.cc)
target_link_libraries(helloworld ${CERES_LIBRARIES})

-----------------------------------------------------------------------
2.  helloworld.cc (for example)
-----------------------------------------------------------------------

C. Make another directory to receive the build, e.g. c:\myPrj-build

D. Open CMake GUI and specify the c:\myPrj and c:\myPrj-build as the "Where is the source code:" and "Where to build the binaries:" directories, respectively.
Press Configure. I had a problem under Ungrouped Entries where the wrong Ceres_Dir was specified. I re-pointed to the dir where I originally built Ceres out.
I then Re-Press Configure. Success. Then Generate.

After this you can open Visual Studio, go to the build directory and find your .sln file which you can then Build in VS.

I didn't do robust testing to make sure that everything is perfect for all contexts, but the base programs do function as expected.

Also, before I could successfully run the created executable, I had to add the path to libglog.dll to my Path statement and reboot as it was having issues finding the dll. Not sure why this was necessary.

[The following results won't exactly match the vanilla helloworld as I changed the model a bit.]
C:\ceres\myPrj-build\Release>helloworld.exe
iter      cost      cost_change  |gradient|   |step|    tr_ratio  tr_radius  ls_
iter  iter_time  total_time
   0  9.901250e+02    0.00e+00    4.45e+01   0.00e+00   0.00e+00  1.00e+04
  0    0.00e+00    0.00e+00
   1  9.899270e-06    9.90e+02    4.45e-03   4.45e+01   1.00e+00  3.00e+04
  1    0.00e+00    0.00e+00
   2  1.099846e-14    9.90e-06    1.48e-07   4.45e-03   1.00e+00  9.00e+04
  1    0.00e+00    0.00e+00
Ceres Solver Report: Iterations: 2, Initial cost: 9.901250e+02, Final cost: 1.09
9846e-14, Termination: CONVERGENCE
x : 0.5 -> 45

Any comments on the steps (especially ways I can do it better) are welcome.

===============================================================================
Reply all
Reply to author
Forward
0 new messages