better handling of filenames

This commit is contained in:
Phuntsok Drak-pa 2019-03-20 12:34:46 +01:00
parent 0295de096d
commit 5f198555f0
4 changed files with 40 additions and 19 deletions

View File

@ -16,14 +16,13 @@ conan_basic_setup()
enable_cxx_compiler_flag_if_supported("-Wall")
enable_cxx_compiler_flag_if_supported("-pedantic")
enable_cxx_compiler_flag_if_supported("-pthread")
# include_directories(<PUBLIC HEADER DIRECTORIES>)
set(TGT genetic-image)
add_executable(${TGT} ${SRC_FILES})
target_compile_features(${TGT} PRIVATE cxx_std_17)
target_include_directories(${TGT} PRIVATE include/genimg)
target_link_libraries(${TGT} ${CONAN_LIBS})
target_link_libraries(${TGT} ${CONAN_LIBS} stdc++fs)
# OS specific instructions.
if(APPLE)

View File

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

View File

@ -1,20 +1,25 @@
#include "common.hh"
#include "parseargs.hh"
#include "drawing.hh"
#include "parseargs.hh"
int main(int ac, char **av) {
auto const [input_file, output_file, video_output, iterations] =
parse_args(ac, av);
spdlog::info("Input file:\t{}", input_file);
spdlog::info("Output file:\t{}", output_file);
spdlog::info("Input file:\t{}", input_file.native());
spdlog::info("Output file:\t{}", output_file.native());
spdlog::info("Video output:\t{}", video_output);
spdlog::info("Iterations:\t{}", iterations);
auto [input_image, process_image] = init_image(input_file);
auto [input_image, process_image] = init_image(input_file.native());
spdlog::info("Euclidian distance: {}",
euclidian_distance(input_image, process_image));
draw_shape(process_image, cv::Point{0, 0}, 10, cv::Scalar(100, 100, 100),
Shapes::Square);
cv::imwrite("some.jpg", process_image);
spdlog::info("Euclidian distance: {}",
euclidian_distance(input_image, process_image));
cv::imwrite(output_file.native(), process_image);
// Launch image generation

View File

@ -2,17 +2,30 @@
#include <boost/program_options.hpp>
#include <cstdlib>
#include <iostream>
#include <string>
constexpr int DEFAULT_ITERATIONS = 5000;
std::tuple<std::string, std::string, bool, int> parse_args(int t_ac,
char **t_av) {
namespace po = boost::program_options;
using path = std::filesystem::path;
namespace po = boost::program_options;
void processFilenames(po::variables_map const &vm, path const &t_input,
path &t_output) {
if (!vm.count("output")) {
t_output.replace_filename("output_" +
std::string{t_input.filename().string()});
} else if (!t_output.has_extension()) {
t_output.replace_extension(".png");
}
if (vm.count("video")) {
t_output.replace_extension(".mp4");
}
}
std::tuple<path, path, bool, int> parse_args(int t_ac, char **t_av) {
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>(),
"input,i", po::value<path>(), "Input image")(
"output,o", po::value<path>(),
"Image or video output path (default: input path + \"_output\")")(
"iterations,n", po::value<int>(),
"Number of iterations (default: 5000)")("video,v", "Enable video output");
@ -23,11 +36,13 @@ std::tuple<std::string, std::string, bool, int> parse_args(int t_ac,
std::cout << desc << "\n";
std::exit(1);
}
auto const input_path = vm["input"].as<path>();
auto output_path =
vm.count("output") ? vm["output"].as<path>() : input_path.filename();
processFilenames(vm, input_path, output_path);
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,
input_path, output_path, vm.count("video") ? true : false,
vm.count("iterations") ? vm["iterations"].as<int>() : DEFAULT_ITERATIONS);
}