forgot to include these files

parent 32d6d425
img/out.png

35.8 KB

#ifndef GENETIC_IMAGE_INCLUDE_GENIMG_METHOD1_METHOD1_HH_
#define GENETIC_IMAGE_INCLUDE_GENIMG_METHOD1_METHOD1_HH_
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <random>
#include <spdlog/spdlog.h>
void method1(cv::Mat &t_reference, cv::Mat &t_output, int t_iterations,
std::mt19937 &t_gen);
#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_METHOD1_METHOD1_HH_ */
#include "method1.hh"
#include "common.hh"
#include "drawing.hh"
#include <algorithm>
using randint = std::uniform_int_distribution<>;
void newSquare(cv::Mat &t_process_img, std::mt19937 &t_gen, randint &t_dist) {
const int square_size = t_dist(t_gen);
auto square_top_left = cv::Point{t_dist(t_gen), t_dist(t_gen)};
// if (auto const diff = t_process_img.size().width - (square_top_left.x +
// square_size);
// diff < 0) {
// square_top_left.x += diff; // += because diff is negative if we reach
// here
// }
draw_shape(t_process_img, square_top_left, square_size, random_color(t_gen),
Shapes::Square);
}
void method1(cv::Mat &t_reference, cv::Mat &t_output, int t_iterations,
std::mt19937 &t_gen) {
auto diff = euclidian_distance(t_reference, t_output);
auto const max_size =
std::max(t_reference.size().width, t_reference.size().height);
randint dist(0, max_size);
spdlog::info("Beginning method1, initial difference: {}", diff);
while (t_iterations > 0) {
auto temp_image = t_output.clone();
newSquare(temp_image, t_gen, dist);
if (auto new_diff = euclidian_distance(t_reference, temp_image);
new_diff < diff) {
diff = new_diff;
temp_image.copyTo(t_output);
--t_iterations;
spdlog::info("Iteration {}: diff {}", t_iterations, diff);
}
}
}
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