better handling of filenames
This commit is contained in:
parent
0295de096d
commit
5f198555f0
@ -16,14 +16,13 @@ conan_basic_setup()
|
|||||||
|
|
||||||
enable_cxx_compiler_flag_if_supported("-Wall")
|
enable_cxx_compiler_flag_if_supported("-Wall")
|
||||||
enable_cxx_compiler_flag_if_supported("-pedantic")
|
enable_cxx_compiler_flag_if_supported("-pedantic")
|
||||||
enable_cxx_compiler_flag_if_supported("-pthread")
|
|
||||||
|
|
||||||
# include_directories(<PUBLIC HEADER DIRECTORIES>)
|
# include_directories(<PUBLIC HEADER DIRECTORIES>)
|
||||||
set(TGT genetic-image)
|
set(TGT genetic-image)
|
||||||
add_executable(${TGT} ${SRC_FILES})
|
add_executable(${TGT} ${SRC_FILES})
|
||||||
target_compile_features(${TGT} PRIVATE cxx_std_17)
|
target_compile_features(${TGT} PRIVATE cxx_std_17)
|
||||||
target_include_directories(${TGT} PRIVATE include/genimg)
|
target_include_directories(${TGT} PRIVATE include/genimg)
|
||||||
target_link_libraries(${TGT} ${CONAN_LIBS})
|
target_link_libraries(${TGT} ${CONAN_LIBS} stdc++fs)
|
||||||
|
|
||||||
# OS specific instructions.
|
# OS specific instructions.
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
#ifndef GENETIC_IMAGE_INCLUDE_GENIMG_PARSEARGS_HH_
|
#ifndef GENETIC_IMAGE_INCLUDE_GENIMG_PARSEARGS_HH_
|
||||||
#define GENETIC_IMAGE_INCLUDE_GENIMG_PARSEARGS_HH_
|
#define GENETIC_IMAGE_INCLUDE_GENIMG_PARSEARGS_HH_
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#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_ */
|
#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_PARSEARGS_HH_ */
|
||||||
|
15
src/main.cc
15
src/main.cc
@ -1,20 +1,25 @@
|
|||||||
#include "common.hh"
|
#include "common.hh"
|
||||||
#include "parseargs.hh"
|
|
||||||
#include "drawing.hh"
|
#include "drawing.hh"
|
||||||
|
#include "parseargs.hh"
|
||||||
|
|
||||||
int main(int ac, char **av) {
|
int main(int ac, char **av) {
|
||||||
auto const [input_file, output_file, video_output, iterations] =
|
auto const [input_file, output_file, video_output, iterations] =
|
||||||
parse_args(ac, av);
|
parse_args(ac, av);
|
||||||
spdlog::info("Input file:\t{}", input_file);
|
spdlog::info("Input file:\t{}", input_file.native());
|
||||||
spdlog::info("Output file:\t{}", output_file);
|
spdlog::info("Output file:\t{}", output_file.native());
|
||||||
spdlog::info("Video output:\t{}", video_output);
|
spdlog::info("Video output:\t{}", video_output);
|
||||||
spdlog::info("Iterations:\t{}", iterations);
|
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),
|
draw_shape(process_image, cv::Point{0, 0}, 10, cv::Scalar(100, 100, 100),
|
||||||
Shapes::Square);
|
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
|
// Launch image generation
|
||||||
|
|
||||||
|
@ -2,17 +2,30 @@
|
|||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
constexpr int DEFAULT_ITERATIONS = 5000;
|
constexpr int DEFAULT_ITERATIONS = 5000;
|
||||||
|
|
||||||
std::tuple<std::string, std::string, bool, int> parse_args(int t_ac,
|
using path = std::filesystem::path;
|
||||||
char **t_av) {
|
namespace po = boost::program_options;
|
||||||
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");
|
po::options_description desc("Allowed options");
|
||||||
desc.add_options()("help,h", "Display this help message")(
|
desc.add_options()("help,h", "Display this help message")(
|
||||||
"input,i", po::value<std::string>(), "Input image")(
|
"input,i", po::value<path>(), "Input image")(
|
||||||
"output,o", po::value<std::string>(),
|
"output,o", po::value<path>(),
|
||||||
"Image or video output path (default: input path + \"_output\")")(
|
"Image or video output path (default: input path + \"_output\")")(
|
||||||
"iterations,n", po::value<int>(),
|
"iterations,n", po::value<int>(),
|
||||||
"Number of iterations (default: 5000)")("video,v", "Enable video output");
|
"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::cout << desc << "\n";
|
||||||
std::exit(1);
|
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(
|
return std::make_tuple(
|
||||||
vm["input"].as<std::string>(),
|
input_path, output_path, vm.count("video") ? true : false,
|
||||||
vm.count("output")
|
|
||||||
? vm["output"].as<std::string>()
|
|
||||||
: vm["input"].as<std::string>() + std::string{"_output"},
|
|
||||||
vm.count("video") ? true : false,
|
|
||||||
vm.count("iterations") ? vm["iterations"].as<int>() : DEFAULT_ITERATIONS);
|
vm.count("iterations") ? vm["iterations"].as<int>() : DEFAULT_ITERATIONS);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user