added helper functions and fixed inverted width and height

This commit is contained in:
Phuntsok Drak-pa 2019-03-20 11:40:17 +01:00
parent 8b7b82f852
commit 0295de096d
4 changed files with 30 additions and 7 deletions

View File

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

View File

@ -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);
}

View File

@ -1,13 +1,28 @@
#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);
}
}

View File

@ -1,5 +1,6 @@
#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;