added helper function for drawing squares

This commit is contained in:
Phuntsok Drak-pa 2019-03-19 15:26:03 +01:00
parent 020d48e16e
commit c96b772e89
2 changed files with 23 additions and 0 deletions

10
include/genimg/drawing.hh Normal file
View File

@ -0,0 +1,10 @@
#ifndef GENETIC_IMAGE_INCLUDE_GENIMG_DRAWING_HH_
#define GENETIC_IMAGE_INCLUDE_GENIMG_DRAWING_HH_
#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);
#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_DRAWING_HH_ */

13
src/drawing.cc Normal file
View File

@ -0,0 +1,13 @@
#include "drawing.hh"
#include <memory>
#include <opencv2/imgproc.hpp>
void draw_square(cv::Mat &t_img, cv::Point const &t_top_left, int const 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};
fillConvexPoly(t_img, points.get(), 4, t_color);
}