Skip to content

Commit e5ada42

Browse files
committed
Replaced boost program_options with cxxopts in fit-model-simple
1 parent 76011bb commit e5ada42

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

examples/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ find_package(OpenCV 4 CONFIG REQUIRED core imgproc imgcodecs)
44
set(Boost_NO_WARN_NEW_VERSIONS ON) # Supress "New Boost version may have incorrect dependencies or import targets" warning
55
find_package(Boost 1.71.0 REQUIRED COMPONENTS program_options)
66

7+
find_package(cxxopts CONFIG REQUIRED)
8+
79
# Simple model fitting (orthographic camera & shape to landmarks) example:
810
add_executable(fit-model-simple fit-model-simple.cpp)
9-
target_link_libraries(fit-model-simple PRIVATE eos opencv_core opencv_imgproc opencv_imgcodecs Boost::program_options)
11+
target_link_libraries(fit-model-simple PRIVATE cxxopts::cxxopts eos opencv_core opencv_imgproc opencv_imgcodecs)
1012
target_link_libraries(fit-model-simple PRIVATE "$<$<CXX_COMPILER_ID:GNU>:-pthread>$<$<CXX_COMPILER_ID:Clang>:-pthreads>")
1113
target_compile_options(fit-model-simple PRIVATE "$<$<CXX_COMPILER_ID:MSVC>:/bigobj>")
1214

examples/fit-model-simple.cpp

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
#include "Eigen/Core"
3333

34-
#include "boost/program_options.hpp"
34+
#include <cxxopts.hpp>
3535

3636
#include "opencv2/core.hpp"
3737
#include "opencv2/imgproc.hpp"
@@ -42,7 +42,6 @@
4242
#include <filesystem>
4343

4444
using namespace eos;
45-
namespace po = boost::program_options;
4645
using eos::core::Landmark;
4746
using eos::core::LandmarkCollection;
4847
using Eigen::Vector2f;
@@ -64,38 +63,44 @@ using std::vector;
6463
*/
6564
int main(int argc, char* argv[])
6665
{
66+
cxxopts::Options options("fit-model-simple",
67+
"A simple example of fitting a 3DMM shape model to 2D landmarks.");
68+
// clang-format off
69+
options.add_options()
70+
("h,help", "display the help message")
71+
("m,model", "a Morphable Model stored as cereal BinaryArchive",
72+
cxxopts::value<std::string>()->default_value("../share/sfm_shape_3448.bin"), "filename")
73+
("i,image", "an input image",
74+
cxxopts::value<std::string>()->default_value("data/image_0010.png"), "filename")
75+
("l,landmarks", "2D landmarks for the image, in ibug .pts format",
76+
cxxopts::value<std::string>()->default_value("data/image_0010.pts"), "filename")
77+
("p,mapping", "landmark identifier to model vertex number mapping",
78+
cxxopts::value<std::string>()->default_value("../share/ibug_to_sfm.txt"), "filename")
79+
("o,output", "basename for the output rendering and obj files",
80+
cxxopts::value<std::string>()->default_value("out"), "basename");
81+
// clang-format on
82+
6783
using std::filesystem::path;
6884
path modelfile, imagefile, landmarksfile, mappingsfile, outputbasename;
85+
6986
try
7087
{
71-
po::options_description desc("Allowed options");
72-
// clang-format off
73-
desc.add_options()
74-
("help,h", "display the help message")
75-
("model,m", po::value<path>(&modelfile)->required()->default_value("../share/sfm_shape_3448.bin"),
76-
"a Morphable Model stored as cereal BinaryArchive")
77-
("image,i", po::value<path>(&imagefile)->required()->default_value("data/image_0010.png"),
78-
"an input image")
79-
("landmarks,l", po::value<path>(&landmarksfile)->required()->default_value("data/image_0010.pts"),
80-
"2D landmarks for the image, in ibug .pts format")
81-
("mapping,p", po::value<path>(&mappingsfile)->required()->default_value("../share/ibug_to_sfm.txt"),
82-
"landmark identifier to model vertex number mapping")
83-
("output,o", po::value<path>(&outputbasename)->required()->default_value("out"),
84-
"basename for the output rendering and obj files");
85-
// clang-format on
86-
po::variables_map vm;
87-
po::store(po::command_line_parser(argc, argv).options(desc).run(), vm);
88-
if (vm.count("help"))
88+
const auto result = options.parse(argc, argv);
89+
if (result.count("help"))
8990
{
90-
cout << "Usage: fit-model-simple [options]" << endl;
91-
cout << desc;
91+
std::cout << options.help() << std::endl;
9292
return EXIT_SUCCESS;
9393
}
94-
po::notify(vm);
95-
} catch (const po::error& e)
94+
95+
modelfile = result["model"].as<std::string>(); // required (with default)
96+
imagefile = result["image"].as<std::string>(); // required (with default)
97+
landmarksfile = result["landmarks"].as<std::string>(); // required (with default)
98+
mappingsfile = result["mapping"].as<std::string>(); // required (with default)
99+
outputbasename = result["output"].as<std::string>(); // required (with default)
100+
} catch (const std::exception& e)
96101
{
97-
cout << "Error while parsing command-line arguments: " << e.what() << endl;
98-
cout << "Use --help to display a list of options." << endl;
102+
std::cout << "Error while parsing command-line arguments: " << e.what() << std::endl;
103+
std::cout << "Use --help to display a list of options." << std::endl;
99104
return EXIT_FAILURE;
100105
}
101106

0 commit comments

Comments
 (0)