added helper functions and fixed inverted width and height
This commit is contained in:
parent
8b7b82f852
commit
0295de096d
@ -4,7 +4,9 @@
|
|||||||
#include <opencv2/core/core.hpp>
|
#include <opencv2/core/core.hpp>
|
||||||
#include <opencv2/highgui/highgui.hpp>
|
#include <opencv2/highgui/highgui.hpp>
|
||||||
|
|
||||||
void draw_square(cv::Mat &t_img, cv::Point const &t_top_left, int const size,
|
enum class Shapes { Square, Circle };
|
||||||
cv::Scalar const &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);
|
||||||
|
|
||||||
#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_DRAWING_HH_ */
|
#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("Image loaded!");
|
||||||
spdlog::info("Width:\t\t{}", input_image.size().width);
|
spdlog::info("Width:\t\t{}", input_image.size().width);
|
||||||
spdlog::info("Height:\t{}", input_image.size().height);
|
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));
|
CV_8UC3, cv::Scalar(0, 0, 0));
|
||||||
return std::make_tuple(std::move(input_image), process_image);
|
return std::make_tuple(std::move(input_image), process_image);
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,28 @@
|
|||||||
#include "drawing.hh"
|
#include "drawing.hh"
|
||||||
|
#include <cstdlib>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <opencv2/imgproc.hpp>
|
#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) {
|
cv::Scalar const &t_color) {
|
||||||
std::unique_ptr<cv::Point> points(new cv::Point[4]);
|
std::unique_ptr<cv::Point> points(new cv::Point[4]);
|
||||||
points.get()[0] = t_top_left;
|
points.get()[0] = t_top_left;
|
||||||
points.get()[1] = cv::Point{t_top_left.x, t_top_left.y + size};
|
points.get()[1] = cv::Point{t_top_left.x, t_top_left.y + t_size};
|
||||||
points.get()[2] = cv::Point{t_top_left.x + size, t_top_left.y + 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 + size, t_top_left.y};
|
points.get()[3] = cv::Point{t_top_left.x + t_size, t_top_left.y};
|
||||||
fillConvexPoly(t_img, points.get(), 4, t_color);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "common.hh"
|
#include "common.hh"
|
||||||
#include "parseargs.hh"
|
#include "parseargs.hh"
|
||||||
|
#include "drawing.hh"
|
||||||
|
|
||||||
int main(int ac, char **av) {
|
int main(int ac, char **av) {
|
||||||
auto const [input_file, output_file, video_output, iterations] =
|
auto const [input_file, output_file, video_output, iterations] =
|
||||||
@ -10,6 +11,11 @@ int main(int ac, char **av) {
|
|||||||
spdlog::info("Iterations:\t{}", iterations);
|
spdlog::info("Iterations:\t{}", iterations);
|
||||||
auto [input_image, process_image] = init_image(input_file);
|
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
|
// Launch image generation
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user