some bugs fixed

This commit is contained in:
Phuntsok Drak-pa 2019-04-27 18:04:32 +02:00
parent b962d50996
commit c75e6a92ea
6 changed files with 37 additions and 40 deletions

View File

@ -2,7 +2,6 @@
#include "shapes.hh" #include "shapes.hh"
#include <spdlog/spdlog.h>
#include <string> #include <string>
#include <vector> #include <vector>

View File

@ -3,6 +3,7 @@
#include <array> #include <array>
#include <opencv2/highgui/highgui.hpp> #include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp> #include <opencv2/imgproc.hpp>
#include <spdlog/spdlog.h>
class Shape class Shape
{ {
@ -31,8 +32,8 @@ public:
Shape &operator=(Shape &&other) noexcept = delete; Shape &operator=(Shape &&other) noexcept = delete;
/// \brief Generates a shape's points /// \brief Generates a shape's points
void operator()(cv::Point &&t_max_pos, int const t_max_size, void update(cv::Point &&t_max_pos, int const t_max_size,
int const t_min_size = 0) noexcept; int const t_min_size = 0) noexcept;
[[nodiscard]] auto get_points() const noexcept [[nodiscard]] auto get_points() const noexcept
-> std::array<cv::Point, Shape::MAX_POINTS> const & -> std::array<cv::Point, Shape::MAX_POINTS> const &

View File

@ -8,6 +8,7 @@
int main(int ac, char **av) int main(int ac, char **av)
{ {
std::srand(std::time(nullptr)); std::srand(std::time(nullptr));
spdlog::set_level(spdlog::level::debug);
auto const arguments = parse_args(ac, av); auto const arguments = parse_args(ac, av);
spdlog::set_level(arguments.verbose ? spdlog::level::debug spdlog::set_level(arguments.verbose ? spdlog::level::debug
: spdlog::level::info); : spdlog::level::info);
@ -15,7 +16,6 @@ int main(int ac, char **av)
spdlog::debug("Input file:\t{}", arguments.input_path.native()); spdlog::debug("Input file:\t{}", arguments.input_path.native());
spdlog::debug("Output file:\t{}", arguments.output_path.native()); spdlog::debug("Output file:\t{}", arguments.output_path.native());
spdlog::debug("Iterations:\t{}", arguments.iterations); spdlog::debug("Iterations:\t{}", arguments.iterations);
ImageManipulator image_process{arguments.input_path, arguments.output_path, ImageManipulator image_process{arguments.input_path, arguments.output_path,
arguments.iterations, arguments.shape}; arguments.iterations, arguments.shape};
image_process.exec_method(arguments.method, arguments.controlled_size, image_process.exec_method(arguments.method, arguments.controlled_size,

View File

@ -202,8 +202,8 @@ ImageManipulator::euclidian_distance(cv::Mat const &t_img) const noexcept
void ImageManipulator::create_shape() noexcept void ImageManipulator::create_shape() noexcept
{ {
shape_(cv::Point{reference_.size().width, reference_.size().height}, shape_.update(cv::Point{reference_.size().width, reference_.size().height},
std::min(reference_.size().width, reference_.size().height)); std::min(reference_.size().width, reference_.size().height));
} }
void ImageManipulator::create_controlled_shape() noexcept void ImageManipulator::create_controlled_shape() noexcept
@ -216,8 +216,8 @@ void ImageManipulator::create_controlled_shape() noexcept
/ 2.0f) / 2.0f)
* coef); * coef);
int const max_size = min_size * 2 + 1; int const max_size = min_size * 2 + 1;
shape_(cv::Point{reference_.size().width, reference_.size().height}, max_size, shape_.update(cv::Point{reference_.size().width, reference_.size().height},
min_size); max_size, min_size);
} }
/** /**

View File

@ -45,26 +45,25 @@ void processFilenames(po::variables_map const &t_vm, path const &t_input,
{ {
ParsedArgs ret{}; ParsedArgs ret{};
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: \"output_\" + input path)")(
"Image output path (default: \"output_\" + input path)") "iterations,n", po::value<int>(), "Number of iterations (default: 2000)")(
("iterations,n", po::value<int>(), "Number of iterations (default: 2000)") "method,m", po::value<int>(), "Method number to be used (default: 1)")(
("method,m", po::value<int>(), "Method number to be used (default: 1)") "form,f", po::value<int>(), "Select shape (1:square, 2:triangle)")(
("form,f", po::value<int>(), "Select shape (1:square, 2:triangle)") "cols,c", po::value<int>(),
("cols,c", po::value<int>(), "For method 5 only, number of columns the reference image should be "
"For method 5 only, number of columns the reference image should be " "divided into. If the value is equal to 0, then it will be assumed "
"divided into. If the value is equal to 0, then it will be assumed " "there will be as many rows as there are collumns. (default: 0)")(
"there will be as many rows as there are collumns. (default: 0)") "rows,r", po::value<int>(),
("rows,r", po::value<int>(), "For method 5 only, number of rows the reference image should be "
"For method 5 only, number of rows the reference image should be " "divided into. (default: 1)")(
"divided into. (default: 1)") "submethod,S", po::value<int>(),
("submethod,S", po::value<int>(), "Sub-method that will be used to generate the individual tiles from "
"Sub-method that will be used to generate the individual tiles from " "method 5. (default: 1)")("size,s",
"method 5. (default: 1)") "Enables controlled size of the random shapes")(
("size,s", "Enables controlled size of the random shapes") "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);
@ -82,10 +81,11 @@ void processFilenames(po::variables_map const &t_vm, path const &t_input,
ret.output_path = output_path; ret.output_path = output_path;
ret.iterations = vm.count("iterations") ? vm["iterations"].as<int>() ret.iterations = vm.count("iterations") ? vm["iterations"].as<int>()
: DEFAULT_ITERATIONS; : DEFAULT_ITERATIONS;
spdlog::debug("arg: {}", vm.count("form") ? vm["form"].as<int>() : 1);
ret.method = vm.count("method") ? vm["method"].as<int>() : 1; ret.method = vm.count("method") ? vm["method"].as<int>() : 1;
switch (vm.count("form") ? vm["form"].as<int>() : 1) { switch (vm.count("form") ? vm["form"].as<int>() : 1) {
case 2: ret.shape = Shape::ShapeType::Triangle; break; case 2: ret.shape = Shape::ShapeType::Triangle; break;
case 1: [[fallthrough]]; case 1: ret.shape = Shape::ShapeType::Square; break;
default: ret.shape = Shape::ShapeType::Square; break; default: ret.shape = Shape::ShapeType::Square; break;
} }

View File

@ -8,11 +8,8 @@ using point_arr = std::array<cv::Point, 4>;
Shape::Shape(Shape::ShapeType const t_type) : type_{t_type} Shape::Shape(Shape::ShapeType const t_type) : type_{t_type}
{ {
switch (t_type) { switch (t_type) {
case ShapeType::Triangle: { case ShapeType::Triangle: nb_points_ = 3; break;
nb_points_ = 3; case ShapeType::Square: nb_points_ = 4; break;
break;
}
case ShapeType::Square: [[fallthrough]];
default: nb_points_ = 4; break; default: nb_points_ = 4; break;
} }
} }
@ -31,8 +28,8 @@ Shape::Shape(Shape &&other) noexcept
* for * for
* \return Array of points describing the shape * \return Array of points describing the shape
*/ */
void Shape::operator()(cv::Point &&t_max_pos, int const t_max_size, void Shape::update(cv::Point &&t_max_pos, int const t_max_size,
int const t_min_size) noexcept int const t_min_size) noexcept
{ {
int const size = (rand() % (t_max_size - t_min_size)) + t_min_size; int const size = (rand() % (t_max_size - t_min_size)) + t_min_size;
cv::Point const top_left cv::Point const top_left
@ -47,11 +44,11 @@ void Shape::operator()(cv::Point &&t_max_pos, int const t_max_size,
void Shape::create_triangle_points(cv::Point const &t_top_left, void Shape::create_triangle_points(cv::Point const &t_top_left,
int const t_size) noexcept int const t_size) noexcept
{ {
bool top_left = rand() % 1 == 0; bool top_left = rand() % 2 == 0;
points_ = { points_ = {
cv::Point{top_left ? t_top_left.x : t_top_left.x + t_size, t_top_left.y}, cv::Point{top_left ? t_top_left.x : t_top_left.x + t_size, t_top_left.y},
cv::Point{top_left ? t_top_left.x + t_size : t_top_left.x, cv::Point{top_left ? t_top_left.x + t_size : t_top_left.x,
t_top_left.y + t_size}, t_top_left.y + rand() % t_size},
cv::Point{t_top_left.x + rand() % t_size, t_top_left.y + t_size}, cv::Point{t_top_left.x + rand() % t_size, t_top_left.y + t_size},
cv::Point{0, 0}}; cv::Point{0, 0}};
} }
@ -61,6 +58,6 @@ void Shape::create_square_points(cv::Point const &t_top_left,
{ {
points_ = {cv::Point{t_top_left.x, t_top_left.y}, points_ = {cv::Point{t_top_left.x, t_top_left.y},
cv::Point{t_top_left.x, t_top_left.y + t_size}, cv::Point{t_top_left.x, t_top_left.y + t_size},
cv::Point{t_top_left.x + t_size, t_top_left.y}, cv::Point{t_top_left.x + t_size, t_top_left.y + t_size},
cv::Point{t_top_left.x + t_size, t_top_left.y}}; cv::Point{t_top_left.x + t_size, t_top_left.y}};
} }