some bugs fixed
This commit is contained in:
parent
b962d50996
commit
c75e6a92ea
@ -2,7 +2,6 @@
|
||||
|
||||
#include "shapes.hh"
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <array>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
class Shape
|
||||
{
|
||||
@ -31,8 +32,8 @@ public:
|
||||
Shape &operator=(Shape &&other) noexcept = delete;
|
||||
|
||||
/// \brief Generates a shape's points
|
||||
void operator()(cv::Point &&t_max_pos, int const t_max_size,
|
||||
int const t_min_size = 0) noexcept;
|
||||
void update(cv::Point &&t_max_pos, int const t_max_size,
|
||||
int const t_min_size = 0) noexcept;
|
||||
|
||||
[[nodiscard]] auto get_points() const noexcept
|
||||
-> std::array<cv::Point, Shape::MAX_POINTS> const &
|
||||
|
@ -8,6 +8,7 @@
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
std::srand(std::time(nullptr));
|
||||
spdlog::set_level(spdlog::level::debug);
|
||||
auto const arguments = parse_args(ac, av);
|
||||
spdlog::set_level(arguments.verbose ? spdlog::level::debug
|
||||
: spdlog::level::info);
|
||||
@ -15,7 +16,6 @@ int main(int ac, char **av)
|
||||
spdlog::debug("Input file:\t{}", arguments.input_path.native());
|
||||
spdlog::debug("Output file:\t{}", arguments.output_path.native());
|
||||
spdlog::debug("Iterations:\t{}", arguments.iterations);
|
||||
|
||||
ImageManipulator image_process{arguments.input_path, arguments.output_path,
|
||||
arguments.iterations, arguments.shape};
|
||||
image_process.exec_method(arguments.method, arguments.controlled_size,
|
||||
|
@ -202,8 +202,8 @@ ImageManipulator::euclidian_distance(cv::Mat const &t_img) const noexcept
|
||||
|
||||
void ImageManipulator::create_shape() noexcept
|
||||
{
|
||||
shape_(cv::Point{reference_.size().width, reference_.size().height},
|
||||
std::min(reference_.size().width, reference_.size().height));
|
||||
shape_.update(cv::Point{reference_.size().width, reference_.size().height},
|
||||
std::min(reference_.size().width, reference_.size().height));
|
||||
}
|
||||
|
||||
void ImageManipulator::create_controlled_shape() noexcept
|
||||
@ -216,8 +216,8 @@ void ImageManipulator::create_controlled_shape() noexcept
|
||||
/ 2.0f)
|
||||
* coef);
|
||||
int const max_size = min_size * 2 + 1;
|
||||
shape_(cv::Point{reference_.size().width, reference_.size().height}, max_size,
|
||||
min_size);
|
||||
shape_.update(cv::Point{reference_.size().width, reference_.size().height},
|
||||
max_size, min_size);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,26 +45,25 @@ void processFilenames(po::variables_map const &t_vm, path const &t_input,
|
||||
{
|
||||
ParsedArgs ret{};
|
||||
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: \"output_\" + input path)")
|
||||
("iterations,n", po::value<int>(), "Number of iterations (default: 2000)")
|
||||
("method,m", po::value<int>(), "Method number to be used (default: 1)")
|
||||
("form,f", po::value<int>(), "Select shape (1:square, 2:triangle)")
|
||||
("cols,c", po::value<int>(),
|
||||
"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 "
|
||||
"there will be as many rows as there are collumns. (default: 0)")
|
||||
("rows,r", po::value<int>(),
|
||||
"For method 5 only, number of rows the reference image should be "
|
||||
"divided into. (default: 1)")
|
||||
("submethod,S", po::value<int>(),
|
||||
"Sub-method that will be used to generate the individual tiles from "
|
||||
"method 5. (default: 1)")
|
||||
("size,s", "Enables controlled size of the random shapes")
|
||||
("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: \"output_\" + input path)")(
|
||||
"iterations,n", po::value<int>(), "Number of iterations (default: 2000)")(
|
||||
"method,m", po::value<int>(), "Method number to be used (default: 1)")(
|
||||
"form,f", po::value<int>(), "Select shape (1:square, 2:triangle)")(
|
||||
"cols,c", po::value<int>(),
|
||||
"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 "
|
||||
"there will be as many rows as there are collumns. (default: 0)")(
|
||||
"rows,r", po::value<int>(),
|
||||
"For method 5 only, number of rows the reference image should be "
|
||||
"divided into. (default: 1)")(
|
||||
"submethod,S", po::value<int>(),
|
||||
"Sub-method that will be used to generate the individual tiles from "
|
||||
"method 5. (default: 1)")("size,s",
|
||||
"Enables controlled size of the random shapes")(
|
||||
"verbose,v", "Enables verbosity");
|
||||
po::variables_map vm;
|
||||
po::store(po::parse_command_line(t_ac, t_av, desc), 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.iterations = vm.count("iterations") ? vm["iterations"].as<int>()
|
||||
: DEFAULT_ITERATIONS;
|
||||
spdlog::debug("arg: {}", vm.count("form") ? vm["form"].as<int>() : 1);
|
||||
ret.method = vm.count("method") ? vm["method"].as<int>() : 1;
|
||||
switch (vm.count("form") ? vm["form"].as<int>() : 1) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -8,11 +8,8 @@ using point_arr = std::array<cv::Point, 4>;
|
||||
Shape::Shape(Shape::ShapeType const t_type) : type_{t_type}
|
||||
{
|
||||
switch (t_type) {
|
||||
case ShapeType::Triangle: {
|
||||
nb_points_ = 3;
|
||||
break;
|
||||
}
|
||||
case ShapeType::Square: [[fallthrough]];
|
||||
case ShapeType::Triangle: nb_points_ = 3; break;
|
||||
case ShapeType::Square: nb_points_ = 4; break;
|
||||
default: nb_points_ = 4; break;
|
||||
}
|
||||
}
|
||||
@ -31,8 +28,8 @@ Shape::Shape(Shape &&other) noexcept
|
||||
* for
|
||||
* \return Array of points describing the shape
|
||||
*/
|
||||
void Shape::operator()(cv::Point &&t_max_pos, int const t_max_size,
|
||||
int const t_min_size) noexcept
|
||||
void Shape::update(cv::Point &&t_max_pos, int const t_max_size,
|
||||
int const t_min_size) noexcept
|
||||
{
|
||||
int const size = (rand() % (t_max_size - t_min_size)) + t_min_size;
|
||||
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,
|
||||
int const t_size) noexcept
|
||||
{
|
||||
bool top_left = rand() % 1 == 0;
|
||||
points_ = {
|
||||
bool top_left = rand() % 2 == 0;
|
||||
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_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{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},
|
||||
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}};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user