aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/TCC/Tango.TCC.OpenCV/Utils.cpp
blob: 6e49c315c0fb7b99f060f2b85dbaba7f54b854e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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;
}