Ubuntu20.04安装Ceres1.14版本并测试是否成功 | 您所在的位置:网站首页 › ceres安装少了SuiteSparse组件 › Ubuntu20.04安装Ceres1.14版本并测试是否成功 |
Ceres库的安装
一、添加源
sudo gedit /etc/apt/sources.list
将下面的源粘贴到source.list的最上方 ,保存退出 deb http://cz.archive.ubuntu.com/ubuntu trusty main universe更新 sudo apt-get update 二、安装依赖库 sudo apt-get install liblapack-dev libsuitesparse-dev libcxsparse3.1.2 libgflags-dev sudo apt-get install libgoogle-glog-dev libgtest-dev 三、下载Ceres1.14版本并解压 wget ceres-solver.org/ceres-solver-1.14.0.tar.gz tar -zxvf ceres-solver-1.14.0.tar.gz 四、编译安装 cd ceres-solver-1.14.0 mkdir build cd build cmake .. make -j4 sudo make install 测试Ceres库是否安装成功编写CMakeLists.txt cmake_minimum_required(VERSION 3.8.0) project(ceres_example) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Ceres REQUIRED) include_directories( ${CERES_INCLUDE_DIRS} ) add_executable(ceres_example ceres_example.cpp) target_link_libraries(ceres_example ${CERES_LIBRARIES} )ceres官网一个例子 #include class CostFunctor { public: template bool operator()(const T* const x, T* residual) const { residual[0] = 10.0 - x[0]; return true; } }; int main(int argc, char const* argv[]) { double initial_x = 5.0; double x = initial_x; // Build the problem. ceres::Problem problem; // Set up the only cost function (also known as residual). This uses // auto-differentiation to obtain the derivative (jacobian). ceres::CostFunction* cost_function = new ceres::AutoDiffCostFunction(new CostFunctor); problem.AddResidualBlock(cost_function, nullptr, &x); // Run the solver! ceres::Solver::Options options; options.linear_solver_type = ceres::DENSE_QR; options.minimizer_progress_to_stdout = true; ceres::Solver::Summary summary; Solve(options, &problem, &summary); std::cout |
CopyRight 2018-2019 实验室设备网 版权所有 |