forgot to include these files

This commit is contained in:
Phuntsok Drak-pa 2019-03-20 20:15:53 +01:00
parent 32d6d42585
commit f6387a241b
3 changed files with 51 additions and 0 deletions

BIN
img/out.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

12
include/genimg/method1.hh Normal file
View File

@ -0,0 +1,12 @@
#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_ */

39
src/method1.cc Normal file
View File

@ -0,0 +1,39 @@
#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);
}
}
}