genetic-images/src/drawing.cc

32 lines
1.1 KiB
C++
Raw Normal View History

#include "drawing.hh"
#include <cstdlib>
#include <memory>
#include <opencv2/imgproc.hpp>
#include <spdlog/spdlog.h>
void drawSquare(cv::Mat &t_img, cv::Point const &t_top_left, int const t_size,
2019-03-25 11:24:19 +00:00
cv::Scalar const &t_color) {
auto points = std::make_unique<cv::Point[]>(4);
points.get()[0] = t_top_left;
2019-03-25 11:24:19 +00:00
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};
2019-03-25 11:24:19 +00:00
// spdlog::debug("Size:{} 1[{},{}] 2[{},{}] 3[{},{}] 4[{},{}]", t_size,
// points[0].x, points[0].y, points[1].x, points[1].y, points[2].x,
// points[2].y, points[3].x, points[3].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);
}
}