40 lines
1.3 KiB
C++
40 lines
1.3 KiB
C++
#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);
|
|
}
|
|
}
|
|
}
|