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"
4242#include < filesystem>
4343
4444using namespace eos ;
45- namespace po = boost::program_options;
4645using eos::core::Landmark;
4746using eos::core::LandmarkCollection;
4847using Eigen::Vector2f;
@@ -64,38 +63,44 @@ using std::vector;
6463 */
6564int 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