1.下載
您可以從最新的穩定版本開始 latest stable release。或者,如果您想要最新版本,可以克隆git存儲庫
git clone https://ceres-solver.googlesource.com/ceres-solver
2.安裝 Linux
安裝依賴
# CMake
sudo apt-get install cmake
# google-glog + gflags
sudo apt-get install libgoogle-glog-dev
# BLAS & LAPACK
sudo apt-get install libatlas-base-dev
# Eigen3
sudo apt-get install libeigen3-dev
# SuiteSparse and CXSparse (optional)
# - If you want to build Ceres as a *static* library (the default)
# you can use the SuiteSparse package in the main Ubuntu package
# repository:
sudo apt-get install libsuitesparse-dev
# - However, if you want to build Ceres as a *shared* library, you must
# add the following PPA:
sudo add-apt-repository ppa:bzindovic/suitesparse-bugfix-1319687
sudo apt-get update
sudo apt-get install libsuitesparse-dev
安裝
tar zxf ceres-solver-1.14.0.tar.gz
mkdir ceres-bin
cd ceres-bin
cmake ../ceres-solver-1.14.0
make -j3
make test
# Optionally install Ceres, it can also be exported using CMake which
# allows Ceres to be used without requiring installation, see the documentation
# for the EXPORT_BUILD_DIR option for more information.
make install
您還可以嘗試運行命令行捆綁應用程序,其中包含一個包含的問題,這些問題來自華盛頓大學的BAL數據集[Agarwal]。
- bin/simple_bundle_adjuster ../ceres-solver-1.14.0/data/problem-16-22106-pre.txt
3.在cmake 中使用
1.Ceres必須已安裝make install,
如果安裝位置是非標準的(即不在CMake的默認搜索路徑中),默認情況下不會檢測到,請參閱
請注意,如果您使用的是非標準安裝位置,則應考慮導出Ceres,因爲這不需要在客戶端代碼中提供任何額外信息以便檢測Ceres。
2.或者Ceres的構建目錄必須通過啓用導出EXPORT_BUILD_DIR
Ceres配置時的選項。
簡單helloworld
find_package(Ceres REQUIRED)
include_directories(${CERES_INCLUDE_DIRS})
# helloworld
add_executable(helloworld helloworld.cc)
target_link_libraries(helloworld ${CERES_LIBRARIES})
ros包增加
find_package(Ceres REQUIRED COMPONENTS SuiteSparse)
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC
"${CERES_INCLUDE_DIRS}")
target_link_libraries(${PROJECT_NAME} PUBLIC ${CERES_LIBRARIES})
在調用find_package(Ceres)時,您可以指定所需的特定Ceres組件(以便將Ceres報告爲已找到)。 這允許您指定,例如,您需要使用SuiteSparse支持構建的Ceres版本。 根據定義,如果在調用find_package(Ceres)時沒有指定任何組件(默認值),則檢測到的任何Ceres版本都將被報告爲found,而不管它是使用哪個組件構建的。
LAPACK
: Ceres built using LAPACK (LAPACK=ON
).SuiteSparse
: Ceres built with SuiteSparse (SUITESPARSE=ON
).CXSparse
: Ceres built with CXSparse (CXSPARSE=ON
).EigenSparse
: Ceres built with Eigen’s sparse Cholesky factorization (EIGENSPARSE=ON
).SparseLinearAlgebraLibrary
: Ceres built with at least one sparse linear algebra library. This is equivalent toSuiteSparse
ORCXSparse
OREigenSparse
.SchurSpecializations
: Ceres built with Schur specializations (SCHUR_SPECIALIZATIONS=ON
).OpenMP
: Ceres built with OpenMP (OPENMP=ON
).TBB
: Ceres built with Intel Thread Building Blocks (TBB) (TBB=ON
).Multithreading
: Ceres built with a multithreading library. This is equivalent toOpenMP
ORTBB
.C++11
: Ceres built with C++11 (CXX11=ON
).
要指定一個/多個Ceres組件,請使用COMPONENTS參數find_package(),如下所示:
find_package(Ceres REQUIRED COMPONENTS SuiteSparse EigenSparse)
4.指定Ceres版本
此外,當CMake找到Ceres時,它可以選擇檢查包版本,如果已在find_package()調用中指定。例如:
find_package(Ceres 1.2.3 REQUIRED)
本地安裝
如果通過指定-DCMAKE_INSTALL_PREFIX =“/ some / where / local”將Ceres安裝在非標準路徑中,則用戶應將PATHS選項添加到find_package()命令,例如,
find_package(Ceres REQUIRED PATHS "/some/where/local/")
請注意,這可用於安裝多個版本的Ceres。 但是,特別是如果您只想使用單個版本的Ceres但不希望安裝到系統位置,則應考慮使用EXPORT_BUILD_DIR選項而不是本地安裝來導出Ceres,因爲Ceres的導出版本將是 由CMake自動檢測,無論其位置如何。