2019-04-13 12:26:01 +00:00
|
|
|
#pragma once
|
2019-03-20 19:15:53 +00:00
|
|
|
|
2019-04-13 12:26:01 +00:00
|
|
|
#include <filesystem>
|
2019-03-20 19:15:53 +00:00
|
|
|
#include <opencv2/core/core.hpp>
|
|
|
|
#include <opencv2/highgui/highgui.hpp>
|
2019-04-13 12:26:01 +00:00
|
|
|
#include <opencv2/imgproc.hpp>
|
2019-03-28 11:39:33 +00:00
|
|
|
#include <spdlog/spdlog.h>
|
2019-04-13 12:26:01 +00:00
|
|
|
#include <string>
|
|
|
|
#include <thread>
|
2019-04-02 08:37:14 +00:00
|
|
|
#include <tuple>
|
|
|
|
#include <vector>
|
|
|
|
|
2019-04-13 12:26:01 +00:00
|
|
|
class ImageManipulator {
|
|
|
|
public:
|
|
|
|
ImageManipulator() = delete;
|
2019-04-13 17:46:04 +00:00
|
|
|
ImageManipulator(const ImageManipulator& other);
|
|
|
|
ImageManipulator(ImageManipulator&& other) noexcept;
|
|
|
|
[[nodiscard]] auto operator=(const ImageManipulator& other)
|
|
|
|
-> ImageManipulator;
|
|
|
|
[[nodiscard]] auto operator=(ImageManipulator&& other) noexcept
|
|
|
|
-> ImageManipulator;
|
2019-04-13 12:26:01 +00:00
|
|
|
|
|
|
|
// Load image from input, and prepare for output
|
|
|
|
ImageManipulator(std::filesystem::path const t_input_path,
|
|
|
|
std::filesystem::path const t_output_path,
|
|
|
|
int const iterations);
|
2019-04-13 17:46:04 +00:00
|
|
|
ImageManipulator(cv::Mat const& t_origin_image,
|
|
|
|
int const iterations,
|
|
|
|
int const t_x,
|
|
|
|
int const t_y,
|
|
|
|
int const t_width,
|
|
|
|
int const t_height);
|
2019-04-13 12:26:01 +00:00
|
|
|
|
2019-04-13 17:46:04 +00:00
|
|
|
void exec_method(int const t_nb_method,
|
|
|
|
bool const t_controlled_size,
|
|
|
|
int const t_cols,
|
|
|
|
int const t_rows,
|
|
|
|
int const t_submethod);
|
2019-04-13 12:26:01 +00:00
|
|
|
void write_file() const;
|
2019-04-13 17:46:04 +00:00
|
|
|
[[nodiscard]] auto const& get_generated_image() const noexcept
|
|
|
|
{
|
|
|
|
return generated_image_;
|
|
|
|
}
|
2019-04-13 12:26:01 +00:00
|
|
|
|
|
|
|
//! Destructor
|
|
|
|
virtual ~ImageManipulator() noexcept = default;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
private:
|
|
|
|
[[nodiscard]] auto euclidian_distance(cv::Mat const& t_img) const noexcept
|
|
|
|
-> double;
|
|
|
|
[[nodiscard]] auto random_color() const noexcept;
|
|
|
|
[[nodiscard]] auto get_square_values() const noexcept;
|
|
|
|
[[nodiscard]] auto get_controlled_square_values() const noexcept;
|
|
|
|
[[nodiscard]] auto create_candidate(bool const t_controlled_size) const;
|
|
|
|
|
|
|
|
void get_color_set();
|
|
|
|
void threaded_get_color(int t_h);
|
|
|
|
void adjust_size(cv::Point& t_top_left, int const size) noexcept;
|
|
|
|
void draw_square(cv::Mat& t_img,
|
|
|
|
cv::Point const& t_top_left,
|
|
|
|
int const t_size,
|
|
|
|
cv::Scalar const& t_color) const;
|
2019-04-13 17:46:04 +00:00
|
|
|
void update_gen_image(cv::Mat const& t_img, double const t_diff);
|
2019-04-13 12:26:01 +00:00
|
|
|
void method1();
|
|
|
|
void method2();
|
|
|
|
void method3();
|
|
|
|
void method4(bool const t_controlled_size);
|
2019-04-13 17:46:04 +00:00
|
|
|
void method5(bool const t_controlled_size,
|
|
|
|
int cols,
|
|
|
|
int const rows,
|
|
|
|
int const submethod);
|
2019-04-13 12:26:01 +00:00
|
|
|
|
|
|
|
std::vector<std::array<uchar, 3>> colors_
|
|
|
|
= std::vector<std::array<uchar, 3>>{};
|
|
|
|
cv::Mat const reference_;
|
2019-04-13 17:46:04 +00:00
|
|
|
cv::Mat generated_image_
|
|
|
|
= cv::Mat{reference_.size().height, reference_.size().width, CV_8UC3,
|
|
|
|
cv::Scalar(0, 0, 0)};
|
|
|
|
mutable std::mutex colors_mutex_ = std::mutex{};
|
|
|
|
std::string const output_path_{""};
|
2019-04-13 12:26:01 +00:00
|
|
|
double diff_ = 0.0;
|
|
|
|
int const total_iterations_ = 0;
|
2019-04-13 17:46:04 +00:00
|
|
|
int remaining_iter_ = total_iterations_;
|
|
|
|
int const width_ = reference_.size().width;
|
|
|
|
int const height_ = reference_.size().height;
|
2019-04-13 12:26:01 +00:00
|
|
|
};
|