#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; }