first naive method implemented

parent e31b761b
......@@ -3,12 +3,15 @@
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <spdlog/spdlog.h>
#include <string>
#include <tuple>
#include <spdlog/spdlog.h>
#include <random>
std::tuple<cv::Mat, cv::Mat> init_image(std::string const &);
std::tuple<cv::Mat, cv::Mat> init_image(std::string const &t_input_file);
double euclidian_distance(cv::Mat const &, cv::Mat const &);
double euclidian_distance(cv::Mat const &t_img1, cv::Mat const &t_img2);
cv::Scalar random_color(std::mt19937 &);
#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_COMMON_HH_ */
......@@ -6,7 +6,7 @@
enum class Shapes { Square, Circle };
void draw_shape(cv::Mat &t_img, cv::Point const &t_top_left, int const t_size,
cv::Scalar const &t_color, Shapes const &t_shape);
void draw_shape(cv::Mat &, cv::Point const &, int const, cv::Scalar const &,
Shapes const &);
#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_DRAWING_HH_ */
......@@ -5,7 +5,7 @@
#include <string>
#include <tuple>
std::tuple<std::filesystem::path, std::filesystem::path, bool, int>
std::tuple<std::filesystem::path, std::filesystem::path, bool, int, int>
parse_args(int, char **);
#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_PARSEARGS_HH_ */
......@@ -28,3 +28,8 @@ double euclidian_distance(cv::Mat const &t_img1, cv::Mat const &t_img2) {
euclidian = std::sqrt(euclidian);
return euclidian;
}
cv::Scalar random_color(std::mt19937 &t_gen) {
static std::uniform_int_distribution<> dis(0, 255);
return cv::Scalar(dis(t_gen), dis(t_gen), dis(t_gen));
}
#include "common.hh"
#include "drawing.hh"
#include "method1.hh"
#include "parseargs.hh"
int main(int ac, char **av) {
auto const [input_file, output_file, video_output, iterations] =
auto const [input_file, output_file, video_output, iterations, method] =
parse_args(ac, av);
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.native());
spdlog::info("Euclidian distance: {}",
euclidian_distance(input_image, process_image));
std::random_device rd;
std::mt19937 gen(rd());
draw_shape(process_image, cv::Point{0, 0}, 10, cv::Scalar(100, 100, 100),
Shapes::Square);
spdlog::info("Euclidian distance: {}",
euclidian_distance(input_image, process_image));
switch (method) {
case 1: {
method1(input_image, process_image, iterations, gen);
break;
}
default:
spdlog::error("Requested method {} is not implemented.");
std::exit(-1);
}
cv::imwrite(output_file.native(), process_image);
......
......@@ -21,14 +21,16 @@ void processFilenames(po::variables_map const &vm, path const &t_input,
}
}
std::tuple<path, path, bool, int> parse_args(int t_ac, char **t_av) {
std::tuple<path, path, bool, int, 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<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");
desc.add_options()
("help,h", "Display this help message")
("input,i", po::value<path>(), "Input image")
("output,o", po::value<path>(),
"Image or video 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)")
("video,v", "Enable video output");
po::variables_map vm;
po::store(po::parse_command_line(t_ac, t_av, desc), vm);
po::notify(vm);
......@@ -43,6 +45,9 @@ std::tuple<path, path, bool, int> parse_args(int t_ac, char **t_av) {
processFilenames(vm, input_path, output_path);
return std::make_tuple(
input_path, output_path, vm.count("video") ? true : false,
vm.count("iterations") ? vm["iterations"].as<int>() : DEFAULT_ITERATIONS);
input_path,
output_path,
vm.count("video") ? true : false,
vm.count("iterations") ? vm["iterations"].as<int>() : DEFAULT_ITERATIONS,
vm.count("method") ? vm["method"].as<int>() : 1);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment