We saw in the previous section that computing Haar features involves calculating the sum of pixel intensity values over arbitrary rectangular regions placed over various parts of the image. Now, the naive way to accomplish this would be to traverse the rectangular region of interest (using nested for loops) and compute the sum. Here is what you would typically write in C++ to implement such behavior:
int sumOfRectRegionNaive(Mat image, int x, int y, int height, int width) { int sum = 0; for (int i = x; i < (x + height); ++i) { for (int j = y; j < (y + width); ++j) sum += image.at<uchar>(i, j); } return sum; }
As you can see, the function that we have just defined takes the following inputs:
The image
The x and y coordinates of the upper-left corner of the rectangular region
The width and height of the rectangular region of interest
The function returns the sum of intensity values of all...