moved image initialization to new files

This commit is contained in:
Phuntsok Drak-pa 2019-03-19 14:49:57 +01:00
parent 7018d217f3
commit 020d48e16e
4 changed files with 31 additions and 12 deletions

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

@ -0,0 +1,12 @@
#ifndef GENETIC_IMAGE_INCLUDE_GENIMG_COMMON_HH_
#define GENETIC_IMAGE_INCLUDE_GENIMG_COMMON_HH_
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <string>
#include <tuple>
#include <spdlog/spdlog.h>
std::tuple<cv::Mat, cv::Mat> init_image(const std::string &t_input_file);
#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_COMMON_HH_ */

17
src/common.cc Normal file
View File

@ -0,0 +1,17 @@
#include "common.hh"
#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);
if (!input_image.data) {
spdlog::critical("Could not open or find image!\n");
exit(-1);
}
spdlog::info("Image loaded!");
spdlog::info("Width:\t\t{}", input_image.size().width);
spdlog::info("Height:\t{}", input_image.size().height);
cv::Mat process_image(input_image.size().width, input_image.size().height,
CV_8UC3, cv::Scalar(0, 0, 0));
return std::make_tuple(std::move(input_image), process_image);
}

View File

@ -1,8 +1,5 @@
#include "parseargs.hh"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <spdlog/spdlog.h>
#include <string>
#include "common.hh"
int main(int ac, char **av) {
const auto [input_file, output_file, video_output, iterations] =
@ -11,14 +8,7 @@ int main(int ac, char **av) {
spdlog::info("Output file:\t{}", output_file);
spdlog::info("Video output:\t{}", video_output);
spdlog::info("Iterations:\t{}", iterations);
cv::Mat image = cv::imread(input_file, cv::IMREAD_COLOR); // Read the file
if (!image.data) { // Check for invalid input
spdlog::critical("Could not open or find image!\n");
return -1;
}
spdlog::info("Image loaded!");
spdlog::info("Width:\t{}", image.size().width);
spdlog::info("Height:\t{}", image.size().height);
auto [input_image, process_image] = init_image(input_file);
return 0;
}