added helper functions and fixed inverted width and height

parent 8b7b82f8
......@@ -4,7 +4,9 @@
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
void draw_square(cv::Mat &t_img, cv::Point const &t_top_left, int const size,
cv::Scalar const &t_color);
enum class Shapes { Square, Circle };
void draw_shape(cv::Mat &t_img, cv::Point const &t_top_left, int const t_size,
cv::Scalar const &t_color, Shapes const &t_shape);
#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_DRAWING_HH_ */
......@@ -12,7 +12,7 @@ std::tuple<cv::Mat, cv::Mat> init_image(std::string const &t_input_file) {
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::Mat process_image(input_image.size().height, input_image.size().width,
CV_8UC3, cv::Scalar(0, 0, 0));
return std::make_tuple(std::move(input_image), process_image);
}
......
#include "drawing.hh"
#include <cstdlib>
#include <memory>
#include <opencv2/imgproc.hpp>
#include <spdlog/spdlog.h>
void draw_square(cv::Mat &t_img, cv::Point const &t_top_left, int const size,
void drawSquare(cv::Mat &t_img, cv::Point const &t_top_left, int const t_size,
cv::Scalar const &t_color) {
std::unique_ptr<cv::Point> points(new cv::Point[4]);
points.get()[0] = t_top_left;
points.get()[1] = cv::Point{t_top_left.x, t_top_left.y + size};
points.get()[2] = cv::Point{t_top_left.x + size, t_top_left.y + size};
points.get()[3] = cv::Point{t_top_left.x + size, t_top_left.y};
points.get()[1] = cv::Point{t_top_left.x, t_top_left.y + t_size};
points.get()[2] = cv::Point{t_top_left.x + t_size, t_top_left.y + t_size};
points.get()[3] = cv::Point{t_top_left.x + t_size, t_top_left.y};
fillConvexPoly(t_img, points.get(), 4, t_color);
}
void draw_shape(cv::Mat &t_img, cv::Point const &t_top_left, int const t_size,
cv::Scalar const &t_color, Shapes const &t_shape) {
switch (t_shape) {
case Shapes::Square: {
drawSquare(t_img, t_top_left, t_size, t_color);
break;
}
default:
spdlog::error("Shape does not exist. Aborting...");
std::exit(1);
}
}
#include "common.hh"
#include "parseargs.hh"
#include "drawing.hh"
int main(int ac, char **av) {
auto const [input_file, output_file, video_output, iterations] =
......@@ -10,6 +11,11 @@ int main(int ac, char **av) {
spdlog::info("Iterations:\t{}", iterations);
auto [input_image, process_image] = init_image(input_file);
draw_shape(process_image, cv::Point{0, 0}, 10, cv::Scalar(100, 100, 100),
Shapes::Square);
cv::imwrite("some.jpg", process_image);
// Launch image generation
return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment