edited some functions' signature (best practices)

This commit is contained in:
Phuntsok Drak-pa 2019-03-27 13:33:22 +01:00
parent 491a4f73b1
commit fe530235a2
5 changed files with 20 additions and 16 deletions

View File

@ -7,8 +7,9 @@
#include <string> #include <string>
#include <utility> #include <utility>
std::pair<cv::Mat, cv::Mat> init_image(std::string const &); [[nodiscard]] std::pair<cv::Mat, cv::Mat>
init_image(std::string const &) noexcept;
double euclidian_distance(cv::Mat const &, cv::Mat const &); [[nodiscard]] double euclidian_distance(cv::Mat const &, cv::Mat const &);
#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_COMMON_HH_ */ #endif /* GENETIC_IMAGE_INCLUDE_GENIMG_COMMON_HH_ */

View File

@ -4,7 +4,8 @@
#include <filesystem> #include <filesystem>
#include <tuple> #include <tuple>
std::tuple<std::filesystem::path, std::filesystem::path, int, int, bool> [[nodiscard]] std::tuple<std::filesystem::path, std::filesystem::path, int, int,
bool>
parse_args(int, char **); parse_args(int, char **);
#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_PARSEARGS_HH_ */ #endif /* GENETIC_IMAGE_INCLUDE_GENIMG_PARSEARGS_HH_ */

View File

@ -3,7 +3,8 @@
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
std::pair<cv::Mat, cv::Mat> init_image(std::string const &t_input_file) { [[nodiscard]] std::pair<cv::Mat, cv::Mat>
init_image(std::string const &t_input_file) noexcept {
cv::Mat input_image = cv::imread(t_input_file, cv::IMREAD_COLOR); cv::Mat input_image = cv::imread(t_input_file, cv::IMREAD_COLOR);
if (!input_image.data) { if (!input_image.data) {
spdlog::critical("Could not open or find image!\n"); spdlog::critical("Could not open or find image!\n");
@ -17,7 +18,8 @@ std::pair<cv::Mat, cv::Mat> init_image(std::string const &t_input_file) {
return std::make_pair(std::move(input_image), process_image); return std::make_pair(std::move(input_image), process_image);
} }
double euclidian_distance(cv::Mat const &t_img1, cv::Mat const &t_img2) { [[nodiscard]] double euclidian_distance(cv::Mat const &t_img1,
cv::Mat const &t_img2) {
double euclidian = 0.0; double euclidian = 0.0;
for (auto itr1 = t_img1.begin<uchar>(), itr2 = t_img2.begin<uchar>(); for (auto itr1 = t_img1.begin<uchar>(), itr2 = t_img2.begin<uchar>();
itr1 != t_img1.end<uchar>() && itr2 != t_img2.end<uchar>(); itr1 != t_img1.end<uchar>() && itr2 != t_img2.end<uchar>();

View File

@ -30,7 +30,7 @@ void adjustSize(cv::Mat const &t_process_img, cv::Point &t_top_left, int size) {
} }
} }
cv::Scalar randomColor() { [[nodiscard]] cv::Scalar randomColor() {
static std::uniform_int_distribution<> dis(0, 255); static std::uniform_int_distribution<> dis(0, 255);
return cv::Scalar(rand() % 255, rand() % 255, rand() % 255); return cv::Scalar(rand() % 255, rand() % 255, rand() % 255);
} }
@ -56,7 +56,7 @@ void threadedGetColor(cv::Mat &t_reference, ColorSet &t_colors, int t_h) {
} }
} }
ColorSet getColorSet(cv::Mat &t_reference) { [[nodiscard]] ColorSet getColorSet(cv::Mat &t_reference) {
ColorSet res{}; ColorSet res{};
for (int h = 0; h < t_reference.size().height; h += thread_nbr) { for (int h = 0; h < t_reference.size().height; h += thread_nbr) {
std::vector<std::thread> thread_list{}; std::vector<std::thread> thread_list{};

View File

@ -18,16 +18,16 @@ void processFilenames(po::variables_map const &vm, path const &t_input,
} }
} }
std::tuple<path, path, int, int, bool> parse_args(int t_ac, char **t_av) { [[nodiscard]] std::tuple<path, path, int, int, bool> parse_args(int t_ac,
char **t_av) {
po::options_description desc("Allowed options"); po::options_description desc("Allowed options");
desc.add_options() desc.add_options()("help,h", "Display this help message")(
("help,h", "Display this help message") "input,i", po::value<path>(),
("input,i", po::value<path>(), "Input image") "Input image")("output,o", po::value<path>(),
("output,o", po::value<path>(), "Image output path (default: input path + \"_output\")")(
"Image output path (default: input path + \"_output\")") "method,m", po::value<int>(), "Method number to be used (default: 1)")(
("method,m", po::value<int>(), "Method number to be used (default: 1)") "iterations,n", po::value<int>(),
("iterations,n", po::value<int>(), "Number of iterations (default: 5000)") "Number of iterations (default: 5000)")("verbose,v", "Enables verbosity");
("verbose,v", "Enables verbosity");
po::variables_map vm; po::variables_map vm;
po::store(po::parse_command_line(t_ac, t_av, desc), vm); po::store(po::parse_command_line(t_ac, t_av, desc), vm);
po::notify(vm); po::notify(vm);