From e5ada425367f1a91c7bad6e189ba17d0e2be93bf Mon Sep 17 00:00:00 2001 From: Patrik Huber Date: Sun, 15 Dec 2024 11:15:24 +0000 Subject: [PATCH] Replaced boost program_options with cxxopts in fit-model-simple --- examples/CMakeLists.txt | 4 ++- examples/fit-model-simple.cpp | 57 +++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 2996cf0b..55d86f85 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -4,9 +4,11 @@ find_package(OpenCV 4 CONFIG REQUIRED core imgproc imgcodecs) set(Boost_NO_WARN_NEW_VERSIONS ON) # Supress "New Boost version may have incorrect dependencies or import targets" warning find_package(Boost 1.71.0 REQUIRED COMPONENTS program_options) +find_package(cxxopts CONFIG REQUIRED) + # Simple model fitting (orthographic camera & shape to landmarks) example: add_executable(fit-model-simple fit-model-simple.cpp) -target_link_libraries(fit-model-simple PRIVATE eos opencv_core opencv_imgproc opencv_imgcodecs Boost::program_options) +target_link_libraries(fit-model-simple PRIVATE cxxopts::cxxopts eos opencv_core opencv_imgproc opencv_imgcodecs) target_link_libraries(fit-model-simple PRIVATE "$<$:-pthread>$<$:-pthreads>") target_compile_options(fit-model-simple PRIVATE "$<$:/bigobj>") diff --git a/examples/fit-model-simple.cpp b/examples/fit-model-simple.cpp index d32e7b0c..bdd89f27 100644 --- a/examples/fit-model-simple.cpp +++ b/examples/fit-model-simple.cpp @@ -31,7 +31,7 @@ #include "Eigen/Core" -#include "boost/program_options.hpp" +#include #include "opencv2/core.hpp" #include "opencv2/imgproc.hpp" @@ -42,7 +42,6 @@ #include using namespace eos; -namespace po = boost::program_options; using eos::core::Landmark; using eos::core::LandmarkCollection; using Eigen::Vector2f; @@ -64,38 +63,44 @@ using std::vector; */ int main(int argc, char* argv[]) { + cxxopts::Options options("fit-model-simple", + "A simple example of fitting a 3DMM shape model to 2D landmarks."); + // clang-format off + options.add_options() + ("h,help", "display the help message") + ("m,model", "a Morphable Model stored as cereal BinaryArchive", + cxxopts::value()->default_value("../share/sfm_shape_3448.bin"), "filename") + ("i,image", "an input image", + cxxopts::value()->default_value("data/image_0010.png"), "filename") + ("l,landmarks", "2D landmarks for the image, in ibug .pts format", + cxxopts::value()->default_value("data/image_0010.pts"), "filename") + ("p,mapping", "landmark identifier to model vertex number mapping", + cxxopts::value()->default_value("../share/ibug_to_sfm.txt"), "filename") + ("o,output", "basename for the output rendering and obj files", + cxxopts::value()->default_value("out"), "basename"); + // clang-format on + using std::filesystem::path; path modelfile, imagefile, landmarksfile, mappingsfile, outputbasename; + try { - po::options_description desc("Allowed options"); - // clang-format off - desc.add_options() - ("help,h", "display the help message") - ("model,m", po::value(&modelfile)->required()->default_value("../share/sfm_shape_3448.bin"), - "a Morphable Model stored as cereal BinaryArchive") - ("image,i", po::value(&imagefile)->required()->default_value("data/image_0010.png"), - "an input image") - ("landmarks,l", po::value(&landmarksfile)->required()->default_value("data/image_0010.pts"), - "2D landmarks for the image, in ibug .pts format") - ("mapping,p", po::value(&mappingsfile)->required()->default_value("../share/ibug_to_sfm.txt"), - "landmark identifier to model vertex number mapping") - ("output,o", po::value(&outputbasename)->required()->default_value("out"), - "basename for the output rendering and obj files"); - // clang-format on - po::variables_map vm; - po::store(po::command_line_parser(argc, argv).options(desc).run(), vm); - if (vm.count("help")) + const auto result = options.parse(argc, argv); + if (result.count("help")) { - cout << "Usage: fit-model-simple [options]" << endl; - cout << desc; + std::cout << options.help() << std::endl; return EXIT_SUCCESS; } - po::notify(vm); - } catch (const po::error& e) + + modelfile = result["model"].as(); // required (with default) + imagefile = result["image"].as(); // required (with default) + landmarksfile = result["landmarks"].as(); // required (with default) + mappingsfile = result["mapping"].as(); // required (with default) + outputbasename = result["output"].as(); // required (with default) + } catch (const std::exception& e) { - cout << "Error while parsing command-line arguments: " << e.what() << endl; - cout << "Use --help to display a list of options." << endl; + std::cout << "Error while parsing command-line arguments: " << e.what() << std::endl; + std::cout << "Use --help to display a list of options." << std::endl; return EXIT_FAILURE; }