Arguments parsed

This commit is contained in:
Phuntsok Drak-pa 2019-03-19 13:49:37 +01:00
parent 41310135f4
commit 15c02c852d
4 changed files with 51 additions and 16 deletions

View File

@ -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):

View File

@ -1,24 +1,24 @@
#include "parseargs.hh"
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <string>
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;
}

26
src/parseargs.cc Normal file
View File

@ -0,0 +1,26 @@
#include "parseargs.hh"
#include <boost/program_options.hpp>
#include <cstdlib>
#include <iostream>
#include <string>
std::tuple<std::string, std::string, bool> 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<std::string>(), "Input image")(
"output,o", po::value<std::string>(),
"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<std::string>(),
(vm.count("output")) ? vm["output"].as<std::string>()
: vm["input"].as<std::string>() +
std::string{"_output"},
(vm.count("video")) ? true : false);
}

9
src/parseargs.hh Normal file
View File

@ -0,0 +1,9 @@
#ifndef GENETIC_IMAGE_INCLUDE_GENIMG_PARSEARGS_HH_
#define GENETIC_IMAGE_INCLUDE_GENIMG_PARSEARGS_HH_
#include <string>
#include <tuple>
std::tuple<std::string, std::string, bool> parse_args(int, char**);
#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_PARSEARGS_HH_ */