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 <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_ */

View File

@ -4,7 +4,8 @@
#include <filesystem>
#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 **);
#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_PARSEARGS_HH_ */

View File

@ -3,7 +3,8 @@
#include <cmath>
#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);
if (!input_image.data) {
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);
}
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;
for (auto itr1 = t_img1.begin<uchar>(), itr2 = t_img2.begin<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);
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{};
for (int h = 0; h < t_reference.size().height; h += thread_nbr) {
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");
desc.add_options()
("help,h", "Display this help message")
("input,i", po::value<path>(), "Input image")
("output,o", po::value<path>(),
"Image output path (default: input path + \"_output\")")
("method,m", po::value<int>(), "Method number to be used (default: 1)")
("iterations,n", po::value<int>(), "Number of iterations (default: 5000)")
("verbose,v", "Enables verbosity");
desc.add_options()("help,h", "Display this help message")(
"input,i", po::value<path>(),
"Input image")("output,o", po::value<path>(),
"Image output path (default: input path + \"_output\")")(
"method,m", po::value<int>(), "Method number to be used (default: 1)")(
"iterations,n", po::value<int>(),
"Number of iterations (default: 5000)")("verbose,v", "Enables verbosity");
po::variables_map vm;
po::store(po::parse_command_line(t_ac, t_av, desc), vm);
po::notify(vm);