method 5 DONE

parent 51bac1bd
#pragma once
#include <filesystem>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <spdlog/spdlog.h>
#include <string>
#include <thread>
#include <tuple>
#include <vector>
class ImageManipulator {
public:
ImageManipulator() = delete;
/// \brief Copy contructor
ImageManipulator(const ImageManipulator& other);
/// \brief Move constructor
ImageManipulator(ImageManipulator&& other) noexcept;
[[nodiscard]] auto operator=(const ImageManipulator& other)
-> ImageManipulator;
[[nodiscard]] auto operator=(ImageManipulator&& other) noexcept
-> ImageManipulator;
// Load image from input, and prepare for output
ImageManipulator(std::filesystem::path const t_input_path,
std::filesystem::path const t_output_path,
/// \brief Load image from input, and prepare for output
ImageManipulator(std::string const t_input_path,
std::string const t_output_path,
int const iterations);
/// \brief Basically makes views from image
ImageManipulator(cv::Mat const& t_origin_image,
int const iterations,
int const t_x,
......@@ -31,57 +30,96 @@ class ImageManipulator {
int const t_width,
int const t_height);
/// \brief Copy assignment operator
[[nodiscard]] auto operator=(const ImageManipulator& other)
-> ImageManipulator;
/// \brief Move assignment operator
[[nodiscard]] auto operator=(ImageManipulator&& other) noexcept
-> ImageManipulator;
/// \brief Execute the nth method on the current object
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);
/// \brief Write the generated image to the output path
void write_file() const;
/// \brief Returns a reference to the generated image
[[nodiscard]] auto const& get_generated_image() const noexcept
{
return generated_image_;
}
//! Destructor
/// \brief Destructor
virtual ~ImageManipulator() noexcept = default;
protected:
private:
/// \brief Calculates the euclidian distance between two images
[[nodiscard]] auto euclidian_distance(cv::Mat const& t_img) const noexcept
-> double;
/// \brief Creates and returns a random color
[[nodiscard]] auto random_color() const noexcept;
/// \brief Generates random square coordinates
[[nodiscard]] auto get_square_values() const noexcept;
/// \brief Generates controlled random square coordinates
[[nodiscard]] auto get_controlled_square_values() const noexcept;
/// \brief Generates a candidate for image generation improvement
[[nodiscard]] auto create_candidate(bool const t_controlled_size) const;
[[nodiscard]] auto generate_tiles(int const t_cols, int const t_rows) const;
/// \brief Gets all colors from the reference image
void get_color_set();
/// \brief Threaded helper for \ref get_color_set
void threaded_get_color(int t_h);
void adjust_size(cv::Point& t_top_left, int const size) noexcept;
/// \brief Draw a square on an image
void draw_square(cv::Mat& t_img,
cv::Point const& t_top_left,
int const t_size,
cv::Scalar const& t_color) const;
/// \brief Update this object’s generated image
void update_gen_image(cv::Mat const& t_img, double const t_diff);
void merge_tiles(std::vector<std::vector<ImageManipulator>> t_tiles);
/// \brief First method as described in the
/// [report](https://labs.phundrak.fr/phundrak/genetic-images/blob/master/report/report.pdf)
void method1();
/// \brief Second method as described in the
/// [report](https://labs.phundrak.fr/phundrak/genetic-images/blob/master/report/report.pdf)
void method2();
/// \brief Third method as described in the
/// [report](https://labs.phundrak.fr/phundrak/genetic-images/blob/master/report/report.pdf)
void method3();
/// \brief Fourth method as described in the
/// [report](https://labs.phundrak.fr/phundrak/genetic-images/blob/master/report/report.pdf)
void method4(bool const t_controlled_size);
/// \brief Fifth method as described in the
/// [report](https://labs.phundrak.fr/phundrak/genetic-images/blob/master/report/report.pdf)
void method5(bool const t_controlled_size,
int cols,
int const cols,
int const rows,
int const submethod);
std::vector<std::array<uchar, 3>> colors_
= std::vector<std::array<uchar, 3>>{};
cv::Mat const reference_;
= std::vector<std::array<uchar, 3>>{}; /*!< Color set from reference */
cv::Mat const reference_; /*!< Reference image */
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_{""};
double diff_ = 0.0;
int const total_iterations_ = 0;
int remaining_iter_ = total_iterations_;
int const width_ = reference_.size().width;
int const height_ = reference_.size().height;
cv::Scalar(0, 0, 0)}; /*!< Working, generated image */
mutable std::mutex colors_mutex_
= std::mutex{}; /*!< Thread mutex for color set generation */
std::string const output_path_{""}; /*!< Write path for the generated image */
double diff_ = euclidian_distance(generated_image_); /*!< Euclidian difference
between \ref reference_ and \ref generated_image_ */
int const total_iterations_ = 0; /*!< Number of iterations to perform */
int remaining_iter_
= total_iterations_; /*!< Remaining iterations to perform */
int const width_ = reference_.size().width; /*!< Width of the image */
int const height_ = reference_.size().height; /*!< Height of the image */
};
......@@ -3,6 +3,7 @@
#include <filesystem>
#include <tuple>
/// \brief Parses the arguments passed to the program
[[nodiscard]] auto parse_args(int, char**) -> std::tuple<std::filesystem::path,
std::filesystem::path,
int,
......
This diff is collapsed.
#include "parseargs.hh"
#include <boost/program_options.hpp>
#include <cstdlib>
#include <iostream>
constexpr int DEFAULT_ITERATIONS = 2000;
......@@ -8,11 +7,23 @@ constexpr int DEFAULT_ITERATIONS = 2000;
using path = std::filesystem::path;
namespace po = boost::program_options;
void processFilenames(po::variables_map const& vm,
/**
* \brief Ensures correct output path
*
* Checks if an output file exists, and if yes if it has an extension. In case
* it doesn’t exist, `output_` is appended at the beginning of the input
* filename. If the output path does not have an extension, the type `.png` is
* appended at the end of the path.
*
* \param[in] t_vm Arguments passed to the program
* \param[out] t_input Input path
* \param[out] t_output Output path
*/
void processFilenames(po::variables_map const& t_vm,
path const& t_input,
path& t_output)
{
if (!vm.count("output")) {
if (!t_vm.count("output")) {
t_output.replace_filename("output_"
+ std::string{t_input.filename().string()});
}
......@@ -21,6 +32,16 @@ void processFilenames(po::variables_map const& vm,
}
}
/**
* Parses the arguments given to the program, formats them and returns them as
* a tuple. If `-h` or `--help` or a malformed argument is passed, then the
* list of arguments and their comment will be displayed, and the program will
* exit.
*
* \param[in] t_ac Number of arguments passed to the program
* \param[in] t_av Arguments passed to the program
* \return Tuple of path, path, int, int, int, int, int, bool and bool
*/
[[nodiscard]] auto parse_args(int t_ac, char** t_av)
-> std::tuple<path, path, int, int, int, int, int, bool, bool>
{
......
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