New coding style

This commit is contained in:
Phuntsok Drak-pa 2019-03-28 12:26:05 +01:00
parent 9192e89241
commit 912eafb9dd
10 changed files with 308 additions and 250 deletions

32
.clang-format Normal file
View File

@ -0,0 +1,32 @@
---
BasedOnStyle: Chromium
AlignEscapedNewlinesLeft: 'true'
AlignTrailingComments: 'true'
AllowShortBlocksOnASingleLine: 'true'
AllowShortIfStatementsOnASingleLine: 'false'
AllowShortLoopsOnASingleLine: 'false'
AlwaysBreakBeforeMultilineStrings: 'true'
AlwaysBreakTemplateDeclarations: 'true'
BreakBeforeBinaryOperators: 'true'
BreakBeforeBraces: Stroustrup
BreakBeforeTernaryOperators: 'true'
BreakConstructorInitializersBeforeComma: 'false'
ColumnLimit: '80'
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
Cpp11BracedListStyle: 'true'
IndentCaseLabels: 'true'
KeepEmptyLinesAtTheStartOfBlocks: 'false'
Language: Cpp
MaxEmptyLinesToKeep: '2'
PointerAlignment: Left
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: 'false'
SpacesInAngles: 'false'
SpacesInCStyleCastParentheses: 'false'
SpacesInParentheses: 'false'
Standard: Cpp11
TabWidth: '2'
UseTab: ForIndentation
...

View File

@ -1,15 +1,15 @@
#ifndef GENETIC_IMAGE_INCLUDE_GENIMG_COMMON_HH_ #ifndef GENETIC_IMAGE_INCLUDE_GENIMG_COMMON_HH_
#define GENETIC_IMAGE_INCLUDE_GENIMG_COMMON_HH_ #define GENETIC_IMAGE_INCLUDE_GENIMG_COMMON_HH_
#include <spdlog/spdlog.h>
#include <opencv2/core/core.hpp> #include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp> #include <opencv2/highgui/highgui.hpp>
#include <spdlog/spdlog.h>
#include <string> #include <string>
#include <utility> #include <utility>
[[nodiscard]] std::pair<cv::Mat, cv::Mat> [[nodiscard]] std::pair<cv::Mat, cv::Mat> init_image(
init_image(std::string const &) noexcept; std::string const&) noexcept;
[[nodiscard]] double euclidian_distance(cv::Mat const &, cv::Mat const &); [[nodiscard]] double euclidian_distance(cv::Mat const&, cv::Mat const&);
#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_COMMON_HH_ */ #endif /* GENETIC_IMAGE_INCLUDE_GENIMG_COMMON_HH_ */

View File

@ -6,7 +6,10 @@
enum class Shapes { Square, Circle }; enum class Shapes { Square, Circle };
void draw_shape(cv::Mat &, cv::Point const &, int const, cv::Scalar const &, void draw_shape(cv::Mat&,
Shapes const &); cv::Point const&,
int const,
cv::Scalar const&,
Shapes const&);
#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_DRAWING_HH_ */ #endif /* GENETIC_IMAGE_INCLUDE_GENIMG_DRAWING_HH_ */

View File

@ -1,14 +1,14 @@
#ifndef GENETIC_IMAGE_INCLUDE_GENIMG_METHODS_HH_ #ifndef GENETIC_IMAGE_INCLUDE_GENIMG_METHODS_HH_
#define GENETIC_IMAGE_INCLUDE_GENIMG_METHODS_HH_ #define GENETIC_IMAGE_INCLUDE_GENIMG_METHODS_HH_
#include <spdlog/spdlog.h>
#include <opencv2/core/core.hpp> #include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp> #include <opencv2/highgui/highgui.hpp>
#include <spdlog/spdlog.h>
void method1(cv::Mat const &, cv::Mat &, int); void method1(cv::Mat const&, cv::Mat&, int);
void method2(cv::Mat const &, cv::Mat &, int); void method2(cv::Mat const&, cv::Mat&, int);
void method3(cv::Mat const &, cv::Mat &, int); void method3(cv::Mat const&, cv::Mat&, int);
#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_METHODS_HH_ */ #endif /* GENETIC_IMAGE_INCLUDE_GENIMG_METHODS_HH_ */

View File

@ -4,8 +4,8 @@
#include <filesystem> #include <filesystem>
#include <tuple> #include <tuple>
[[nodiscard]] std::tuple<std::filesystem::path, std::filesystem::path, int, int, [[nodiscard]] std::
bool> tuple<std::filesystem::path, std::filesystem::path, int, int, bool>
parse_args(int, char **); parse_args(int, char**);
#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_PARSEARGS_HH_ */ #endif /* GENETIC_IMAGE_INCLUDE_GENIMG_PARSEARGS_HH_ */

View File

@ -3,29 +3,31 @@
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
[[nodiscard]] std::pair<cv::Mat, cv::Mat> [[nodiscard]] std::pair<cv::Mat, cv::Mat> init_image(
init_image(std::string const &t_input_file) noexcept { std::string const& t_input_file) noexcept
cv::Mat input_image = cv::imread(t_input_file, cv::IMREAD_COLOR); {
if (!input_image.data) { cv::Mat input_image = cv::imread(t_input_file, cv::IMREAD_COLOR);
spdlog::critical("Could not open or find image!\n"); if (!input_image.data) {
exit(-1); spdlog::critical("Could not open or find image!\n");
} exit(-1);
spdlog::debug("Image loaded!"); }
spdlog::debug("Width:\t\t{}", input_image.size().width); spdlog::debug("Image loaded!");
spdlog::debug("Height:\t{}", input_image.size().height); spdlog::debug("Width:\t\t{}", input_image.size().width);
cv::Mat process_image(input_image.size().height, input_image.size().width, spdlog::debug("Height:\t{}", input_image.size().height);
CV_8UC3, cv::Scalar(0, 0, 0)); cv::Mat process_image(input_image.size().height, input_image.size().width,
return std::make_pair(std::move(input_image), process_image); CV_8UC3, cv::Scalar(0, 0, 0));
return std::make_pair(std::move(input_image), process_image);
} }
[[nodiscard]] double euclidian_distance(cv::Mat const &t_img1, [[nodiscard]] double euclidian_distance(cv::Mat const& t_img1,
cv::Mat const &t_img2) { cv::Mat const& t_img2)
double euclidian = 0.0; {
for (auto itr1 = t_img1.begin<uchar>(), itr2 = t_img2.begin<uchar>(); double euclidian = 0.0;
itr1 != t_img1.end<uchar>() && itr2 != t_img2.end<uchar>(); for (auto itr1 = t_img1.begin<uchar>(), itr2 = t_img2.begin<uchar>();
++itr1, ++itr2) { itr1 != t_img1.end<uchar>() && itr2 != t_img2.end<uchar>();
euclidian += std::pow(*itr1 - *itr2, 2); ++itr1, ++itr2) {
} euclidian += std::pow(*itr1 - *itr2, 2);
euclidian = std::sqrt(euclidian); }
return euclidian; euclidian = std::sqrt(euclidian);
return euclidian;
} }

View File

@ -1,31 +1,35 @@
#include "drawing.hh" #include "drawing.hh"
#include <spdlog/spdlog.h>
#include <cstdlib> #include <cstdlib>
#include <memory> #include <memory>
#include <opencv2/imgproc.hpp> #include <opencv2/imgproc.hpp>
#include <spdlog/spdlog.h>
void drawSquare(cv::Mat &t_img, cv::Point const &t_top_left, int const t_size, void drawSquare(cv::Mat& t_img,
cv::Scalar const &t_color) { cv::Point const& t_top_left,
auto points = std::make_unique<cv::Point[]>(4); int const t_size,
points.get()[0] = t_top_left; cv::Scalar const& t_color)
points.get()[1] = cv::Point{t_top_left.x, t_top_left.y + t_size}; {
points.get()[2] = cv::Point{t_top_left.x + t_size, t_top_left.y + t_size}; auto points = std::make_unique<cv::Point[]>(4);
points.get()[3] = cv::Point{t_top_left.x + t_size, t_top_left.y}; points.get()[0] = t_top_left;
// spdlog::debug("Size:{} 1[{},{}] 2[{},{}] 3[{},{}] 4[{},{}]", t_size, points.get()[1] = cv::Point{t_top_left.x, t_top_left.y + t_size};
// points[0].x, points[0].y, points[1].x, points[1].y, points[2].x, points.get()[2] = cv::Point{t_top_left.x + t_size, t_top_left.y + t_size};
// points[2].y, points[3].x, points[3].y); points.get()[3] = cv::Point{t_top_left.x + t_size, t_top_left.y};
fillConvexPoly(t_img, points.get(), 4, t_color); fillConvexPoly(t_img, points.get(), 4, t_color);
} }
void draw_shape(cv::Mat &t_img, cv::Point const &t_top_left, int const t_size, void draw_shape(cv::Mat& t_img,
cv::Scalar const &t_color, Shapes const &t_shape) { cv::Point const& t_top_left,
switch (t_shape) { int const t_size,
case Shapes::Square: { cv::Scalar const& t_color,
drawSquare(t_img, t_top_left, t_size, t_color); Shapes const& t_shape)
break; {
} switch (t_shape) {
default: case Shapes::Square: {
spdlog::error("Shape does not exist. Aborting..."); drawSquare(t_img, t_top_left, t_size, t_color);
std::exit(1); break;
} }
default:
spdlog::error("Shape does not exist. Aborting...");
std::exit(1);
}
} }

View File

@ -1,38 +1,39 @@
#include "common.hh"
#include "methods.hh"
#include "parseargs.hh"
#include <cstdlib> #include <cstdlib>
#include <ctime> #include <ctime>
#include <iostream> #include <iostream>
#include "common.hh"
#include "methods.hh"
#include "parseargs.hh"
int main(int ac, char **av) { int main(int ac, char** av)
std::srand(std::time(nullptr)); {
auto const [input_file, output_file, iterations, method, verbose] = std::srand(std::time(nullptr));
parse_args(ac, av); auto const [input_file, output_file, iterations, method, verbose]
spdlog::set_level(verbose ? spdlog::level::debug : spdlog::level::info); = parse_args(ac, av);
spdlog::debug("Input file:\t{}", input_file.native()); spdlog::set_level(verbose ? spdlog::level::debug : spdlog::level::info);
spdlog::debug("Output file:\t{}", output_file.native()); spdlog::debug("Input file:\t{}", input_file.native());
spdlog::debug("Iterations:\t{}", iterations); spdlog::debug("Output file:\t{}", output_file.native());
auto [input_image, process_image] = init_image(input_file.native()); spdlog::debug("Iterations:\t{}", iterations);
auto [input_image, process_image] = init_image(input_file.native());
switch (method) { switch (method) {
case 1: { case 1: {
method1(input_image, process_image, iterations); method1(input_image, process_image, iterations);
break; break;
} }
case 2: { case 2: {
method2(input_image, process_image, iterations); method2(input_image, process_image, iterations);
break; break;
} }
case 3: { case 3: {
method3(input_image, process_image, iterations); method3(input_image, process_image, iterations);
break; break;
} }
default: default:
spdlog::error("Requested method {} is not implemented."); spdlog::error("Requested method {} is not implemented.");
std::exit(-1); std::exit(-1);
} }
cv::imwrite(output_file.native(), process_image); cv::imwrite(output_file.native(), process_image);
return 0; return 0;
} }

View File

@ -1,11 +1,11 @@
#include "methods.hh" #include "methods.hh"
#include "common.hh"
#include "drawing.hh"
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <cstdlib> #include <cstdlib>
#include <thread> #include <thread>
#include <vector> #include <vector>
#include "common.hh"
#include "drawing.hh"
auto const thread_nbr = std::thread::hardware_concurrency(); auto const thread_nbr = std::thread::hardware_concurrency();
std::mutex numbers_mutex; std::mutex numbers_mutex;
@ -17,148 +17,161 @@ using std::rand;
namespace methods_private { namespace methods_private {
void adjustSize(cv::Mat const &t_process_img, cv::Point &t_top_left, int size) { void adjustSize(cv::Mat const& t_process_img, cv::Point& t_top_left, int size)
int const height = t_process_img.size().height; {
int const width = t_process_img.size().width; int const height = t_process_img.size().height;
int const shape_total_width = t_top_left.x + size; int const width = t_process_img.size().width;
int const shape_total_height = t_top_left.y + size; int const shape_total_width = t_top_left.x + size;
if (int const diff = shape_total_height - height; diff > 0) { int const shape_total_height = t_top_left.y + size;
t_top_left.y -= diff + 1; if (int const diff = shape_total_height - height; diff > 0) {
} t_top_left.y -= diff + 1;
if (int const diff = shape_total_width - width; diff > 0) { }
t_top_left.x -= diff + 1; if (int const diff = shape_total_width - width; diff > 0) {
} t_top_left.x -= diff + 1;
}
} }
[[nodiscard]] cv::Scalar randomColor() { [[nodiscard]] cv::Scalar randomColor()
static std::uniform_int_distribution<> dis(0, 255); {
return cv::Scalar(rand() % 255, rand() % 255, rand() % 255); static std::uniform_int_distribution<> dis(0, 255);
return cv::Scalar(rand() % 255, rand() % 255, rand() % 255);
} }
void newSquare1(cv::Mat &t_process_img, cv::Point &&t_top_left, int t_size) { void newSquare1(cv::Mat& t_process_img, cv::Point&& t_top_left, int t_size)
adjustSize(t_process_img, t_top_left, t_size); {
draw_shape(t_process_img, t_top_left, t_size, randomColor(), Shapes::Square); adjustSize(t_process_img, t_top_left, t_size);
draw_shape(t_process_img, t_top_left, t_size, randomColor(), Shapes::Square);
} }
void threadedGetColor(cv::Mat const &t_reference, ColorSet &t_colors, int t_h) { void threadedGetColor(cv::Mat const& t_reference, ColorSet& t_colors, int t_h)
if (t_h > t_reference.size().height) {
return; if (t_h > t_reference.size().height)
for (int w = 0; w < t_reference.size().width; w += 3) { return;
Color temp = {t_reference.at<uchar>(t_h, w), for (int w = 0; w < t_reference.size().width; w += 3) {
t_reference.at<uchar>(t_h, w + 1), Color temp
t_reference.at<uchar>(t_h, w + 2)}; = {t_reference.at<uchar>(t_h, w), t_reference.at<uchar>(t_h, w + 1),
auto pos = std::find(std::begin(t_colors), std::end(t_colors), temp); t_reference.at<uchar>(t_h, w + 2)};
if (pos == std::end(t_colors)) { auto pos = std::find(std::begin(t_colors), std::end(t_colors), temp);
numbers_mutex.lock(); if (pos == std::end(t_colors)) {
t_colors.push_back(temp); numbers_mutex.lock();
numbers_mutex.unlock(); t_colors.push_back(temp);
} numbers_mutex.unlock();
} }
}
} }
[[nodiscard]] ColorSet getColorSet(cv::Mat const &t_reference) { [[nodiscard]] ColorSet getColorSet(cv::Mat const& t_reference)
ColorSet res{}; {
for (int h = 0; h < t_reference.size().height; h += thread_nbr) { ColorSet res{};
std::vector<std::thread> thread_list{}; for (int h = 0; h < t_reference.size().height; h += thread_nbr) {
for (int i = 0; i < thread_nbr; ++i) { std::vector<std::thread> thread_list{};
thread_list.push_back(std::thread(methods_private::threadedGetColor, for (int i = 0; i < thread_nbr; ++i) {
std::ref(t_reference), std::ref(res), thread_list.push_back(std::thread(methods_private::threadedGetColor,
h + i)); std::ref(t_reference), std::ref(res),
} h + i));
for (auto &th : thread_list) }
th.join(); for (auto& th : thread_list)
} th.join();
res.shrink_to_fit(); }
return res; res.shrink_to_fit();
return res;
} }
void newSquare2(cv::Mat &t_process_img, cv::Point &&t_top_left, int t_size, void newSquare2(cv::Mat& t_process_img,
Color const &t_color) { cv::Point&& t_top_left,
draw_shape(t_process_img, t_top_left, t_size, int t_size,
cv::Scalar{static_cast<double>(t_color[0]), Color const& t_color)
static_cast<double>(t_color[1]), {
static_cast<double>(t_color[2])}, draw_shape(t_process_img, t_top_left, t_size,
Shapes::Square); cv::Scalar{static_cast<double>(t_color[0]),
static_cast<double>(t_color[1]),
static_cast<double>(t_color[2])},
Shapes::Square);
} }
} // namespace methods_private } // namespace methods_private
void method1(cv::Mat const &t_reference, cv::Mat &t_output, int t_iterations) { void method1(cv::Mat const& t_reference, cv::Mat& t_output, int t_iterations)
auto diff = euclidian_distance(t_reference, t_output); {
spdlog::debug("Beginning method1, initial difference: {}", diff); auto diff = euclidian_distance(t_reference, t_output);
while (t_iterations > 0 && diff >= 0) { spdlog::debug("Beginning method1, initial difference: {}", diff);
auto temp_image = t_output.clone(); while (t_iterations > 0 && diff >= 0) {
int const rand_x = rand() % temp_image.size().width; auto temp_image = t_output.clone();
int const rand_y = rand() % temp_image.size().height; int const rand_x = rand() % temp_image.size().width;
int const size = rand() % std::min(t_reference.size().width - rand_x, int const rand_y = rand() % temp_image.size().height;
t_reference.size().height - rand_y); int const size = rand()
methods_private::newSquare1(temp_image, cv::Point{rand_x, rand_y}, size); % std::min(t_reference.size().width - rand_x,
if (auto const new_diff = euclidian_distance(t_reference, temp_image); t_reference.size().height - rand_y);
new_diff < diff) { methods_private::newSquare1(temp_image, cv::Point{rand_x, rand_y}, size);
diff = new_diff; if (auto const new_diff = euclidian_distance(t_reference, temp_image);
temp_image.copyTo(t_output); new_diff < diff) {
--t_iterations; diff = new_diff;
spdlog::debug("iteration:{} diff:{}", t_iterations, diff); temp_image.copyTo(t_output);
} --t_iterations;
} spdlog::debug("iteration:{} diff:{}", t_iterations, diff);
}
}
} }
void method2(cv::Mat const &t_reference, cv::Mat &t_output, int t_iterations) { void method2(cv::Mat const& t_reference, cv::Mat& t_output, int t_iterations)
auto diff = euclidian_distance(t_reference, t_output); {
spdlog::debug("Beginning method2, initial difference: {}", diff); auto diff = euclidian_distance(t_reference, t_output);
spdlog::debug("Running {} threads.", thread_nbr); spdlog::debug("Beginning method2, initial difference: {}", diff);
auto const colors = methods_private::getColorSet(t_reference); spdlog::debug("Running {} threads.", thread_nbr);
spdlog::debug("{} colors detected.", colors.size()); auto const colors = methods_private::getColorSet(t_reference);
spdlog::debug("{} colors detected.", colors.size());
while (t_iterations > 0) { while (t_iterations > 0) {
auto temp_image = t_output.clone(); auto temp_image = t_output.clone();
int const rand_x = rand() % temp_image.size().width; int const rand_x = rand() % temp_image.size().width;
int const rand_y = rand() % temp_image.size().height; int const rand_y = rand() % temp_image.size().height;
int const size = rand() % std::min(t_reference.size().width - rand_x, int const size = rand()
t_reference.size().height - rand_y); % std::min(t_reference.size().width - rand_x,
methods_private::newSquare2(temp_image, cv::Point{rand_x, rand_y}, size, t_reference.size().height - rand_y);
colors[rand() % colors.size()]); methods_private::newSquare2(temp_image, cv::Point{rand_x, rand_y}, size,
if (auto new_diff = euclidian_distance(t_reference, temp_image); colors[rand() % colors.size()]);
new_diff < diff) { if (auto new_diff = euclidian_distance(t_reference, temp_image);
diff = new_diff; new_diff < diff) {
temp_image.copyTo(t_output); diff = new_diff;
--t_iterations; temp_image.copyTo(t_output);
spdlog::debug("iteration:{} diff:{}", t_iterations, diff); --t_iterations;
} spdlog::debug("iteration:{} diff:{}", t_iterations, diff);
} }
}
} }
void method3(cv::Mat const &t_reference, cv::Mat &t_output, int t_iterations) { void method3(cv::Mat const& t_reference, cv::Mat& t_output, int t_iterations)
auto const init_iter = t_iterations; {
auto diff = euclidian_distance(t_reference, t_output); auto const init_iter = t_iterations;
spdlog::debug("Beginning method2, initial difference: {}", diff); auto diff = euclidian_distance(t_reference, t_output);
spdlog::debug("Running {} threads.", thread_nbr); spdlog::debug("Beginning method2, initial difference: {}", diff);
auto const colors = methods_private::getColorSet(t_reference); spdlog::debug("Running {} threads.", thread_nbr);
spdlog::debug("{} colors detected.", colors.size()); auto const colors = methods_private::getColorSet(t_reference);
spdlog::debug("{} colors detected.", colors.size());
while (t_iterations > 0) { while (t_iterations > 0) {
auto temp_image = t_output.clone(); auto temp_image = t_output.clone();
int const rand_x = rand() % temp_image.size().width; int const rand_x = rand() % temp_image.size().width;
int const rand_y = rand() % temp_image.size().height; int const rand_y = rand() % temp_image.size().height;
float const coef = float const coef
static_cast<float>(t_iterations) / static_cast<float>(init_iter); = static_cast<float>(t_iterations) / static_cast<float>(init_iter);
int const min_size = static_cast<int>( int const min_size = static_cast<int>(
(static_cast<float>( (static_cast<float>(
std::min(t_reference.size().width, t_reference.size().height)) / std::min(t_reference.size().width, t_reference.size().height))
2.0f) * / 2.0f)
coef); * coef);
int const max_size = min_size * 2 + 1; int const max_size = min_size * 2 + 1;
int const size = rand() % (max_size - min_size) + min_size; int const size = rand() % (max_size - min_size) + min_size;
methods_private::newSquare2(temp_image, cv::Point{rand_x, rand_y}, size, methods_private::newSquare2(temp_image, cv::Point{rand_x, rand_y}, size,
colors[rand() % colors.size()]); colors[rand() % colors.size()]);
if (auto new_diff = euclidian_distance(t_reference, temp_image); if (auto new_diff = euclidian_distance(t_reference, temp_image);
new_diff < diff) { new_diff < diff) {
diff = new_diff; diff = new_diff;
temp_image.copyTo(t_output); temp_image.copyTo(t_output);
spdlog::debug("iteration:{} diff:{} size: {} coef:{} min:{} max:{}", spdlog::debug("iteration:{} diff:{} size: {} coef:{} min:{} max:{}",
t_iterations, diff, size, coef, min_size, max_size); t_iterations, diff, size, coef, min_size, max_size);
--t_iterations; --t_iterations;
} }
} }
} }

View File

@ -8,43 +8,46 @@ constexpr int DEFAULT_ITERATIONS = 5000;
using path = std::filesystem::path; using path = std::filesystem::path;
namespace po = boost::program_options; namespace po = boost::program_options;
void processFilenames(po::variables_map const &vm, path const &t_input, void processFilenames(po::variables_map const& vm,
path &t_output) { path const& t_input,
if (!vm.count("output")) { path& t_output)
t_output.replace_filename("output_" + {
std::string{t_input.filename().string()}); if (!vm.count("output")) {
} else if (!t_output.has_extension()) { t_output.replace_filename("output_"
t_output.replace_extension(".png"); + std::string{t_input.filename().string()});
} }
else if (!t_output.has_extension()) {
t_output.replace_extension(".png");
}
} }
[[nodiscard]] std::tuple<path, path, int, int, bool> parse_args(int t_ac, [[nodiscard]] std::tuple<path, path, int, int, bool> parse_args(int t_ac,
char **t_av) { char** t_av)
po::options_description desc("Allowed options"); {
desc.add_options() po::options_description desc("Allowed options");
("help,h", "Display this help message") desc.add_options()("help,h", "Display this help message")(
("input,i", po::value<path>(), "Input image") "input,i", po::value<path>(), "Input image")(
("output,o", po::value<path>(), "output,o", po::value<path>(),
"Image output path (default: input path + \"_output\")") "Image output path (default: input path + \"_output\")")(
("method,m", po::value<int>(), "Method number to be used (default: 1)") "method,m", po::value<int>(), "Method number to be used (default: 1)")(
("iterations,n", po::value<int>(), "Number of iterations (default: 5000)") "iterations,n", po::value<int>(), "Number of iterations (default: 5000)")(
("verbose,v", "Enables verbosity"); "verbose,v", "Enables verbosity");
po::variables_map vm; po::variables_map vm;
po::store(po::parse_command_line(t_ac, t_av, desc), vm); po::store(po::parse_command_line(t_ac, t_av, desc), vm);
po::notify(vm); po::notify(vm);
if (vm.count("help") || !vm.count("input")) { if (vm.count("help") || !vm.count("input")) {
std::cout << desc << "\n"; std::cout << desc << "\n";
std::exit(1); std::exit(1);
} }
auto const input_path = vm["input"].as<path>(); auto const input_path = vm["input"].as<path>();
auto output_path = auto output_path
vm.count("output") ? vm["output"].as<path>() : input_path.filename(); = vm.count("output") ? vm["output"].as<path>() : input_path.filename();
processFilenames(vm, input_path, output_path); processFilenames(vm, input_path, output_path);
return std::make_tuple(input_path, output_path, return std::make_tuple(
vm.count("iterations") ? vm["iterations"].as<int>() input_path, output_path,
: DEFAULT_ITERATIONS, vm.count("iterations") ? vm["iterations"].as<int>() : DEFAULT_ITERATIONS,
vm.count("method") ? vm["method"].as<int>() : 1, vm.count("method") ? vm["method"].as<int>() : 1,
vm.count("verbose") ? true : false); vm.count("verbose") ? true : false);
} }