Integral Images

OpenCV allows you to calculate an integral image easily with the appropriately named cvIntegral() function. An integral image [Viola04] is a data structure that allows rapid summing of subregions. Such summations are useful in many applications; a notable one is the computation of Haar wavelets, which are used in some face recognition and similar algorithms.

void cvIntegral(
   const CvArr* image,
   CvArr*       sum,
   CvArr*       sqsum      = NULL,
   CvArr*       tilted_sum = NULL
);

The arguments to cvIntegral() are the original image as well as pointers to destination images for the results. The argument sum is required; the others, sqsum and tilted_sum, may be provided if desired. (Actually, the arguments need not be images; they could be matrices, but in practice, they are usually images.) When the input image is 8-bit unsigned, the sum or tilted_sum may be 32-bit integer or floating-point arrays. For all other cases, the sum or tilted_sum must be floating-point valued (either 32- or 64-bit). The result "images" must always be floating-point. If the input image is of size W-by-H, then the output images must be of size (W + 1)-by-(H + 1). [86]

An integral image sum has the form:

image with no caption

The optional sqsum image is the sum of squares:

image with no caption

and the tilted_sum is like the sum except that it is for the image rotated ...

Get Learning OpenCV now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.