updated benchmark script and beginning method 5

This commit is contained in:
Phuntsok Drak-pa
2019-04-09 02:20:33 +02:00
parent 41cbb90213
commit 4201e5476e
12 changed files with 174 additions and 90 deletions

View File

@@ -8,8 +8,10 @@
int main(int ac, char** av)
{
std::srand(std::time(nullptr));
auto const [input_file, output_file, iterations, method, verbose]
= parse_args(ac, av);
auto const [input_file, output_file, iterations, method, division,
controlled_size, verbose
] = parse_args(ac, av);
spdlog::set_level(verbose ? spdlog::level::debug : spdlog::level::info);
spdlog::debug("Input file:\t{}", input_file.native());
spdlog::debug("Output file:\t{}", output_file.native());
@@ -29,12 +31,12 @@ int main(int ac, char** av)
method3(input_image, process_image, iterations);
break;
}
case 4: {
method4(input_image, process_image, iterations);
break;
}
case 4: {
method4(input_image, process_image, iterations, controlled_size);
break;
}
default:
spdlog::error("Requested method {} is not implemented.");
spdlog::error("Requested method {} is not implemented.", method);
std::exit(-1);
}

View File

@@ -204,7 +204,10 @@ void method3(cv::Mat const& t_reference, cv::Mat& t_output, int t_iterations)
}
}
void method4(cv::Mat const& t_reference, cv::Mat& t_output, int t_iterations)
void method4(cv::Mat const& t_reference,
cv::Mat& t_output,
int t_iterations,
bool controlled_size)
{
auto const init_iter = t_iterations;
auto diff = euclidian_distance(t_reference, t_output);
@@ -218,27 +221,38 @@ void method4(cv::Mat const& t_reference, cv::Mat& t_output, int t_iterations)
results{};
std::vector<std::pair<cv::Mat, double>> values{};
for (unsigned i = 0; i < thread_nbr; ++i) {
results.push_back(
std::async(std::launch::async, methods_private::createCandidate,
std::ref(t_output), std::ref(t_reference),
std::ref(colors), diff, true, init_iter, t_iterations));
results.push_back(std::async(
std::launch::async, methods_private::createCandidate,
std::ref(t_output), std::ref(t_reference), std::ref(colors), diff,
controlled_size, init_iter, t_iterations));
}
for (auto& elem : results) {
if (auto res = elem.get(); res.has_value() && res->second < diff) {
values.push_back(*res);
values.push_back(*res);
}
}
if(values.size() > 0) {
unsigned best = 0;
for(unsigned i = 0; i < values.size(); ++i) {
if(values[i].second < values[best].second) {
best = i;
}
}
diff = values[best].second;
values[best].first.copyTo(t_output);
--t_iterations;
if (values.size() > 0) {
unsigned best = 0;
for (unsigned i = 0; i < values.size(); ++i) {
if (values[i].second < values[best].second) {
best = i;
}
}
diff = values[best].second;
values[best].first.copyTo(t_output);
--t_iterations;
spdlog::debug("iteration:{} diff:{}", t_iterations, diff);
}
}
}
}
void method5(cv::Mat const& t_reference,
cv::Mat& t_output,
int t_iterations,
int t_nb_tiles,
bool t_controlled_size = false)
{
std::vector<cv::Mat> tiles{static_cast<size_t>(t_nb_tiles * t_nb_tiles)};
int col_width = t_reference.cols / t_nb_tiles;
spdlog::info("collumns of {}px", col_width);
}

View File

@@ -3,7 +3,7 @@
#include <cstdlib>
#include <iostream>
constexpr int DEFAULT_ITERATIONS = 5000;
constexpr int DEFAULT_ITERATIONS = 2000;
using path = std::filesystem::path;
namespace po = boost::program_options;
@@ -22,16 +22,22 @@ void processFilenames(po::variables_map const& vm,
}
[[nodiscard]] auto parse_args(int t_ac, char** t_av)
-> std::tuple<path, path, int, int, bool>
-> std::tuple<path, path, int, int, int, bool, bool>
{
po::options_description desc("Allowed options");
desc.add_options()("help,h", "Display this help message")(
"input,i", po::value<path>(), "Input image")(
"output,o", po::value<path>(),
"Image output path (default: input path + \"_output\")")(
"method,m", po::value<int>(), "Method number to be used (default: 1)")(
"iterations,n", po::value<int>(), "Number of iterations (default: 5000)")(
"verbose,v", "Enables verbosity");
desc.add_options()
("help,h", "Display this help message")
("input,i", po::value<path>(), "Input image")
("output,o", po::value<path>(),
"Image output path (default: \"output_\" + input path)")
("method,m", po::value<int>(), "Method number to be used (default: 1)")
("iterations,n", po::value<int>(), "Number of iterations (default: 2000)")
("size,s", "Controlled size of the random shapes (default: false)")
("division,d", po::value<int>(),
"For method 5, number of regions the reference image should be divided "
"into. For instance, -d4 will divide the reference image into a 4*4 "
"matrice of smaller images. (default: 1)")
("verbose,v", "Enables verbosity");
po::variables_map vm;
po::store(po::parse_command_line(t_ac, t_av, desc), vm);
po::notify(vm);
@@ -49,5 +55,7 @@ void processFilenames(po::variables_map const& vm,
input_path, output_path,
vm.count("iterations") ? vm["iterations"].as<int>() : DEFAULT_ITERATIONS,
vm.count("method") ? vm["method"].as<int>() : 1,
vm.count("division") ? vm["division"].as<int>() : 1,
vm.count("size") ? true : false,
vm.count("verbose") ? true : false);
}