genetic-images/src/drawing.cc

36 lines
1010 B
C++

#include "drawing.hh"
#include <spdlog/spdlog.h>
#include <cstdlib>
#include <memory>
#include <opencv2/imgproc.hpp>
void drawSquare(cv::Mat& t_img,
cv::Point const& t_top_left,
int const t_size,
cv::Scalar const& t_color)
{
auto points = std::make_unique<cv::Point[]>(4);
points.get()[0] = t_top_left;
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);
}
}