## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

No credit card required

# Integral image

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 ...

## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

No credit card required