added euclidian distance calculation between two images

This commit is contained in:
Phuntsok Drak-pa 2019-03-19 17:20:04 +01:00
parent 79284fe473
commit 12dead2d26
3 changed files with 23 additions and 6 deletions

View File

@ -7,6 +7,8 @@
#include <tuple>
#include <spdlog/spdlog.h>
std::tuple<cv::Mat, cv::Mat> init_image(const std::string &t_input_file);
std::tuple<cv::Mat, cv::Mat> init_image(std::string const &t_input_file);
double euclidian_distance(cv::Mat const &t_img1, cv::Mat const &t_img2);
#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_COMMON_HH_ */

View File

@ -1,9 +1,10 @@
#include "common.hh"
#include <cassert>
#include <cmath>
#include <cstdlib>
std::tuple<cv::Mat, cv::Mat> init_image(const std::string &t_input_file) {
cv::Mat input_image =
cv::imread(t_input_file, cv::IMREAD_COLOR);
std::tuple<cv::Mat, cv::Mat> init_image(std::string const &t_input_file) {
cv::Mat input_image = cv::imread(t_input_file, cv::IMREAD_COLOR);
if (!input_image.data) {
spdlog::critical("Could not open or find image!\n");
exit(-1);
@ -15,3 +16,15 @@ std::tuple<cv::Mat, cv::Mat> init_image(const std::string &t_input_file) {
CV_8UC3, cv::Scalar(0, 0, 0));
return std::make_tuple(std::move(input_image), process_image);
}
double euclidian_distance(cv::Mat const &t_img1, cv::Mat const &t_img2) {
double euclidian = 0.0;
for (int w = 0; w < t_img1.size().width; ++w) {
for (int h = 0; h < t_img1.size().height; ++h) {
euclidian += std::abs(std::pow(t_img1.at<uchar>(h, w), 2) -
std::pow(t_img2.at<uchar>(h, w), 2));
}
}
euclidian = std::sqrt(euclidian);
return euclidian;
}

View File

@ -1,8 +1,8 @@
#include "parseargs.hh"
#include "common.hh"
#include "parseargs.hh"
int main(int ac, char **av) {
const auto [input_file, output_file, video_output, iterations] =
auto const [input_file, output_file, video_output, iterations] =
parse_args(ac, av);
spdlog::info("Input file:\t{}", input_file);
spdlog::info("Output file:\t{}", output_file);
@ -10,5 +10,7 @@ int main(int ac, char **av) {
spdlog::info("Iterations:\t{}", iterations);
auto [input_image, process_image] = init_image(input_file);
// Launch image generation
return 0;
}