diff --git a/conanfile.py b/conanfile.py index 6054246..7dacc9a 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,9 +1,9 @@ -from conans import ConanFile, CMake +from conans import CMake, ConanFile class PocoTimerConan(ConanFile): settings = "os", "compiler", "build_type", "arch" - requires = "opencv/4.0.1@conan/stable" + requires = "opencv/4.0.1@conan/stable", "boost/1.69.0@conan/stable" generators = "cmake", "gcc", "txt" def imports(self): diff --git a/src/main.cc b/src/main.cc index 89c5517..0c22c36 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,24 +1,24 @@ +#include "parseargs.hh" + #include #include #include +#include -using namespace std; +int main(int ac, char **av) { + const auto [input_file, output_file, video_output] = parse_args(ac, av); + std::cout << "Input file:\t" << input_file + << "\nOutput file:\t" << output_file + << "\nVideo output:\t" << ((video_output) ? "yes" : "no") << "\n"; -int main(int argc, char **argv) { - if (argc != 2) { - cout << " Usage: display_image ImageToLoadAndDisplay" << endl; + cv::Mat image = cv::imread(input_file, cv::IMREAD_COLOR); // Read the file + if (!image.data) { // Check for invalid input + std::cout << "Could not open or find the image\n"; return -1; } - - cv::Mat image = cv::imread(argv[1], cv::IMREAD_COLOR); // Read the file - - if (!image.data) // Check for invalid input - { - cout << "Could not open or find the image" << std::endl; - return -1; - } else { - cout << "Loaded image!\n"; - } + std::cout << "Loaded image!\n"; + std::cout << "Width: " << image.size().width + << "\tHeight: " << image.size().height << '\n'; return 0; } diff --git a/src/parseargs.cc b/src/parseargs.cc new file mode 100644 index 0000000..a25d6f3 --- /dev/null +++ b/src/parseargs.cc @@ -0,0 +1,26 @@ +#include "parseargs.hh" +#include +#include +#include +#include + +std::tuple parse_args(int t_ac, char **t_av) { + namespace po = boost::program_options; + po::options_description desc("Allowed options"); + desc.add_options()("help,h", "Display this help message")( + "input,i", po::value(), "Input image")( + "output,o", po::value(), + "Image or video output path")("video,v", "Enable video output"); + po::variables_map vm; + po::store(po::parse_command_line(t_ac, t_av, desc), vm); + po::notify(vm); + if (vm.count("help") || !vm.count("input")) { + std::cout << desc << "\n"; + std::exit(1); + } + return std::make_tuple(vm["input"].as(), + (vm.count("output")) ? vm["output"].as() + : vm["input"].as() + + std::string{"_output"}, + (vm.count("video")) ? true : false); +} diff --git a/src/parseargs.hh b/src/parseargs.hh new file mode 100644 index 0000000..566928a --- /dev/null +++ b/src/parseargs.hh @@ -0,0 +1,9 @@ +#ifndef GENETIC_IMAGE_INCLUDE_GENIMG_PARSEARGS_HH_ +#define GENETIC_IMAGE_INCLUDE_GENIMG_PARSEARGS_HH_ + +#include +#include + +std::tuple parse_args(int, char**); + +#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_PARSEARGS_HH_ */