From 7dbd32ddcf6611dec88ef56336b364110b019571 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 26 Mar 2019 12:54:09 +0200 Subject: A lot of work !!!! --- .../Visual_Studio/TCC/Tango.TCC.OpenCV/Utils.cpp | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Software/Visual_Studio/TCC/Tango.TCC.OpenCV/Utils.cpp (limited to 'Software/Visual_Studio/TCC/Tango.TCC.OpenCV/Utils.cpp') diff --git a/Software/Visual_Studio/TCC/Tango.TCC.OpenCV/Utils.cpp b/Software/Visual_Studio/TCC/Tango.TCC.OpenCV/Utils.cpp new file mode 100644 index 000000000..6e49c315c --- /dev/null +++ b/Software/Visual_Studio/TCC/Tango.TCC.OpenCV/Utils.cpp @@ -0,0 +1,41 @@ +#include "Utils.h" + + + +Utils::Utils() +{ +} + + +Utils::~Utils() +{ +} + +Rect Utils::cropRect(Rect rect, Size size) +{ + Point center = (rect.br() + rect.tl())*0.5; + Rect cropped(center.x - size.width / 2, center.y - size.height / 2, size.width, size.height); + return cropped; +} + +Scalar Utils::getRectMeanColor(Mat image, Rect rect) +{ + Point pts[1][4]; + pts[0][0] = Point(rect.x, rect.y); + pts[0][1] = Point(rect.x + rect.width, rect.y); + pts[0][2] = Point(rect.x + rect.width, rect.y + rect.height); + pts[0][3] = Point(rect.x, rect.y + rect.height); + + const Point* points[1] = { pts[0] }; + int npoints = 4; + + // Create the mask with the polygon + Mat1b mask(image.rows, image.cols, uchar(0)); + + fillPoly(mask, points, &npoints, 1, Scalar(255)); + + // Compute the mean with the computed mask + Scalar average = mean(image, mask); + + return average; +} \ No newline at end of file -- cgit v1.3.1