Back to paper library
Paper notesCVPR 2001

Viola–Jones

Eyes Darker Than Cheeks

Original paper

Rapid Object Detection using a Boosted Cascade of Simple Features

Paper authors

Paul Viola · Michael Jones

Publication
CVPR 2001Conference
Cite this paper · BibTeX

The citation identifies the linked source version. It cites the original paper and its authors.

@inproceedings{objectdetectionviolajones2001,
  title = {{Rapid Object Detection using a Boosted Cascade of Simple Features}},
  author = {Paul Viola and Michael Jones},
  year = {2001},
  booktitle = {CVPR},
  url = {https://doi.org/10.1109/CVPR.2001.990517},
  doi = {10.1109/CVPR.2001.990517}
}
On this page

Plenty of people wrote their first face detector with an XML file that ships with OpenCV. Create a cv2.CascadeClassifier, load haarcascade_frontalface_default.xml, call detectMultiScale on a grayscale image, and out comes a list of face boxes.

Open that XML, and the comment at the top reads "Stump-based 24x24 discrete(?) adaboost frontal face detector", signed Rainer Lienhart. The question mark in the parentheses is in the original (even the person who signed it wasn't quite sure). The 24×24 window, the decision tree with a single split (a stump) and AdaBoost all come from this paper by Paul Viola and Michael Jones.

The paper's system processes 15 grayscale images of 384×288 per second on a 700 MHz Pentium III. It doesn't look at skin color, nor does it subtract consecutive frames to find moving regions; a single grayscale image is all it uses. Its detection rate is about the same as the best methods of the time, and it runs roughly 15 times faster than the Rowley neural-network detector, then considered the fastest.

There are three reasons it's fast. A feature that only compares the brightness of rectangles; an image representation that turns the pixel sum of any rectangle into four table lookups; and a cascade of classifiers that knocks the vast majority of background windows out in the first stage or two. All three can be worked through by hand on a single 24×24 window.

Defining the Problem

Hundreds of Thousands of Windows in One Image

The detector in this paper can answer only one question, whether the 24×24 square in front of it is a frontal face. To find faces in a whole photo, you have to place that square at every position and scale it to every size, asking one window at a time. This is the sliding window.

By the paper's scanning rules, how many times do you have to ask for one 384×288 image? The window starts at 24 pixels and grows by 1.25× each time; at 279 pixels it is already close to the image's short side, for 12 scales in total. At the smallest scale the window shifts 1 pixel at a time, and at scale ss it shifts ss pixels, rounded. Adding up the positions over the 12 scales gives about 260,000 windows (this note's estimate). The MIT+CMU dataset the paper actually tests on has 130 images; 75,081,800 windows were scanned in total, and they contain just 507 faces.

That's one face in every 150,000 windows. This ratio dictates two things the detector has to be able to do.

First, every window has to be cheap. At 15 images per second, each image gets only 67 milliseconds; split among tens to hundreds of thousands of windows, each window gets time on the order of microseconds.

Second, the false-positive rate has to be absurdly low. Suppose a classifier makes one mistake for every 14,084 background windows. That sounds accurate, but on MIT+CMU it means 75,081,800/14,084≈5,33175{,}081{,}800 / 14{,}084 \approx 5{,}331 false positives, 41 per image on average. To get down to just a few dozen false positives on the whole test set, the per-window false-positive rate has to be pushed below 10−610^{-6}.

This 1/14,084 is the result of the paper's own first classifier. That classifier used 200 features, had a detection rate of 95%, and took 0.7 seconds to scan a 384×288 image. The most direct way to make it more accurate is to add features, but every added feature is one more computation for every window.

Other methods of the time were stuck between these two demands as well. The neural network of Rowley, Baluja and Kanade judges every window in turn; to speed it up, they trained a separate, coarser network to screen out some positions first. The statistical model of Schneiderman and Kanade has a high detection rate, but runs at one six-hundredth of this paper's speed. Some systems narrowed the search with skin color or frame differences first, which requires color images or video.

So the paper has to answer two questions at once. How can the features for each window cost almost no time? And since the vast majority of windows are obviously background at a glance, can they be spared from running the whole classifier?

Solving the Problem

Rectangle Features

Original Figure 1: four boxes representing detection windows, each holding an example rectangle feature. A is two bars side by side, the right one stippled; B is two blocks stacked vertically, the top one stippled; C is three bars side by side, the middle one stippled; D is a 2×2 grid of four cells, with the top-right and bottom-left cells stippled.
Original Figure 1, Viola and Jones, from PDF page 6 of the MERL technical report TR2004-043 version, scholarly quotation.

The detector doesn't look at pixels directly; it looks at differences in brightness between rectangles. A feature's value is the pixel sum inside the gray rectangles (stippled in the figure) minus the pixel sum inside the white rectangles.

  • Two-rectangle features (A, B): two rectangles of the same size, adjacent horizontally or vertically. They respond to edges, such as a boundary that is dark above and bright below.
  • Three-rectangle features (C): the middle block minus the two sides. They respond to thin bright or dark bars, such as the bridge of the nose.
  • Four-rectangle features (D): the sum of two diagonal blocks minus the sum of the other two.

These features resemble the basis functions of Haar wavelets; the paper calls them Haar-like features, later usually shortened to Haar features. Unlike true Haar basis functions, they don't have to be orthogonal to each other, and the rectangles can be any size and sit anywhere in the window.

How many such features fit in a 24×24 window? Let's count the side-by-side two-rectangle features.

Let each small rectangle be ww wide and hh tall, so the whole feature is 2w2w wide and hh tall. ww can go from 1 to 12 and hh from 1 to 24. Something 2w2w wide has 25−2w25 - 2w horizontal positions in a window 24 cells wide, and something hh tall has 25−h25 - h vertical positions. Adding everything up:

∑w=112(25−2w)×∑h=124(25−h)=144×300=43,200\begin{aligned} &\sum_{w=1}^{12} (25-2w) \times \sum_{h=1}^{24} (25-h)\\ &= 144 \times 300 = 43{,}200 \end{aligned}

The vertically stacked two-rectangle features also number 43,200. A three-rectangle feature is 3w3w wide, with ww from 1 to 8, so the horizontal positions sum to 22+19+⋯+1=9222 + 19 + \cdots + 1 = 92; times 300, that's 27,600, and the same again for the vertical ones. A four-rectangle feature is 2w2w wide and 2h2h tall, giving 144×144=20,736144 \times 144 = 20{,}736.

The five shapes add up to 162,336. The paper says over 180,000; Robust Real-Time Face Detection, the journal version the authors published three years later in IJCV 2004, says 160,000, closer to this count. The journal version fills in many details more completely, and it is cited along the way below as well. Whichever number you take, it is far more than the window's 576 pixels; there are two to three hundred times as many features as pixels.

With this many features, each one needs the pixel sums inside its rectangles. A 12×24 rectangle has 288 pixels, and adding them up by brute force takes 288 additions.

The Integral Image: Four Lookups

An integral image example drawn for this note. On the left, titled Original image i(x, y), is a 5×5 image with rows 3 1 4 1 5, 9 2 6 5 3, 5 8 9 7 9, 3 2 3 8 4 and 6 2 6 4 3; a blue box encloses the nine cells where x and y both run from 1 to 3. An arrow labeled one pass leads to the right, titled Integral image ii(x, y), whose first row is 3 4 8 9 14 and last row 26 41 69 94 118; four orange cells are numbered 1 to 4: (0,0)=3, (3,0)=9, (0,3)=20 and (3,3)=76. The lines below say that adding the blue box directly gives 50, and that four lookups, 76 + 3 − 9 − 20, also give 50.
Drawn for this note from equations (1) and (2) and the four-lookup rule of Section 2.1 of the paper.

At each position (x,y)(x, y), the integral image stores the sum of all pixels above and to the left of it, itself included:

ii(x,y)=∑x′≤x,  y′≤yi(x′,y′)ii(x, y) = \sum_{x' \le x,\; y' \le y} i(x', y')

i(x,y)i(x, y) is the original image, with xx going right and yy going down, both counted from 0. Take ii(1,1)=15ii(1, 1) = 15 on the right of the figure; it is the top-left 2×22 \times 2 block, 3+1+9+23 + 1 + 9 + 2.

The whole integral image can be computed in a single pass. The paper uses two recurrences:

s(x,y)=s(x,y−1)+i(x,y)ii(x,y)=ii(x−1,y)+s(x,y)\begin{aligned} s(x, y) &= s(x, y-1) + i(x, y)\\ ii(x, y) &= ii(x-1, y) + s(x, y) \end{aligned}

s(x,y)s(x, y) is the sum of column xx accumulated from the top down to row yy, with boundary values s(x,−1)=0s(x, -1) = 0 and ii(−1,y)=0ii(-1, y) = 0. Try it once on ii(2,1)ii(2, 1). s(2,1)=4+6=10s(2, 1) = 4 + 6 = 10, the cell to its left is ii(1,1)=15ii(1, 1) = 15, and adding them gives 25, matching the figure. Each pixel takes only two additions.

With the integral image, the sum of any rectangle needs only its four corners. Let the rectangle cover x0…x1x_0 \dots x_1 and y0…y1y_0 \dots y_1:

S=ii(x1,y1)+ii(x0−1,y0−1)−ii(x1,y0−1)−ii(x0−1,y1)\begin{aligned} S &= ii(x_1, y_1) + ii(x_0-1, y_0-1)\\ &\quad - ii(x_1, y_0-1) - ii(x_0-1, y_1) \end{aligned}

ii(x1,y1)ii(x_1, y_1) is everything above and to the left of the bottom-right corner. Subtract the strip above the rectangle (ii(x1,y0−1)ii(x_1, y_0-1), just outside the top-right corner), then the strip to its left (ii(x0−1,y1)ii(x_0-1, y_1), just outside the bottom-left corner). The block at the top left has now been subtracted twice, so ii(x0−1,y0−1)ii(x_0-1, y_0-1) is added back.

The blue box in the figure covers x,yx, y from 1 to 3, and adding its nine pixels directly gives 50. The lookup is ii(3,3)+ii(0,0)−ii(3,0)−ii(0,3)=76+3−9−20=50ii(3,3) + ii(0,0) - ii(3,0) - ii(0,3) = 76 + 3 - 9 - 20 = 50. The paper numbers these four corners 1 to 4 and writes it as 4+1−(2+3)4 + 1 - (2 + 3).

Whether the rectangle is 3×3 or 300×300, it takes four lookups. The two blocks of a two-rectangle feature are adjacent and share two corners, so it needs only 6 lookups; a three-rectangle feature needs 8 and a four-rectangle feature 9.

The integral image brings one more benefit. A feature takes the same number of lookups at any scale, so to find large faces you simply scale up the detector's rectangle coordinates, without shrinking the image. The journal version measured that on the same 700 MHz computer, just shrinking an image into a 12-level pyramid takes 0.05 seconds, about as long as the whole detector takes to process an image.

Lighting has to be handled too. The same face photographed in shadow and in bright light can give rectangle differences several times apart. Every training window is variance-normalized first, and the same has to be done at detection time. The variance of a window is

σ2=1N∑x2−m2\sigma^2 = \frac{1}{N}\sum x^2 - m^2

NN is the number of pixels in the window and mm is the mean. The mean can be looked up in the original image's integral image, and the sum of squares comes from the integral image of a second, "squared" image, so scanning keeps two integral images on hand. Normalization doesn't actually have to change every pixel either; once a feature value is computed, it is multiplied by a coefficient determined by σ\sigma.

AdaBoost: One Feature at a Time

The features are fast to compute now, but 160,000 of them are still too many. The paper's hypothesis is that a very small subset of them is enough to make a good classifier; the hard part is finding which ones.

The authors' approach is to restrict AdaBoost's weak classifiers to looking at a single feature, an idea that comes from Tieu and Viola's work on image retrieval in 2000. (In the conference version archived by MERL, that reference still reads "Anonymous. Anonymous. In Anonymous, 2000." from double-blind review; the real names were only filled in in the journal version.)

The single-feature weak classifier is written as

hj(x)={1pjfj(x)<pjθj0otherwiseh_j(x) = \begin{cases} 1 & p_j f_j(x) < p_j \theta_j \\ 0 & \text{otherwise} \end{cases}

xx is a 24×24 window, fj(x)f_j(x) is the value of the jj-th feature, θj\theta_j is a threshold, and pj∈{+1,−1}p_j \in \{+1, -1\} sets the direction of the inequality. An output of 1 means "face."

Take a concrete feature (ignoring brightness normalization for now). On a 24×24 face, take two horizontal bands of 18×4 = 72 pixels each, the upper one covering the eyes and the lower one the cheeks; the feature value is the upper band minus the lower band. If a face's eyes average a gray level of 70 and its cheeks 120, the feature value is 72×(70−120)=−3,60072 \times (70 - 120) = -3{,}600; on a uniform wall the two bands are about equally bright, and the value is close to 0. With p=+1p = +1 and θ=−1,500\theta = -1{,}500, the face falls below the threshold and gets an output of 1, and the wall gets 0. If the feature were defined as the lower band minus the upper band, the sign would flip; change pp to −1-1 and the decision is exactly the same.

In each round, AdaBoost finds the best (θj,pj)(\theta_j, p_j) for each of the 160,000 features, then picks the one with the lowest weighted error. The whole procedure goes like this.

Initialization. With mm negatives and ll positives, the weights are set to

w1,i={12myi=012lyi=1w_{1,i} = \begin{cases} \dfrac{1}{2m} & y_i = 0 \\[6pt] \dfrac{1}{2l} & y_i = 1 \end{cases}

Positives and negatives each get half of the total weight. With the paper's final training data, the positives are 4,916 faces plus their mirror images, 9,832 in all, each weighted 1/19,664≈5.09×10−51/19{,}664 \approx 5.09 \times 10^{-5}; the 10,000 negatives are each weighted 5×10−55 \times 10^{-5}.

Each round t=1,…,Tt = 1, \dots, T:

  1. Normalize the weights into a probability distribution, wt,i←wt,i/∑jwt,jw_{t,i} \leftarrow w_{t,i} / \sum_{j} w_{t,j}.

  2. For each feature jj, train a single-feature classifier hjh_j, with weighted error

    ϵj=∑iwt,i∣hj(xi)−yi∣\epsilon_j = \sum_i w_{t,i} \left| h_j(x_i) - y_i \right|
  3. Pick the hth_t with the lowest error, and call its error ϵt\epsilon_t.

  4. Update the weights:

    wt+1,i=wt,i βt 1−ei,βt=ϵt1−ϵtw_{t+1,i} = w_{t,i}\, \beta_t^{\,1 - e_i},\qquad \beta_t = \frac{\epsilon_t}{1 - \epsilon_t}

    Correctly classified samples have ei=0e_i = 0, and their weights are multiplied by βt\beta_t; misclassified ones have ei=1e_i = 1, and their weights stay the same.

The final strong classifier is a weighted vote:

h(x)={1∑t=1Tαtht(x)≥12∑t=1Tαt0otherwiseh(x) = \begin{cases} 1 & \sum_{t=1}^{T} \alpha_t h_t(x) \ge \dfrac{1}{2}\sum_{t=1}^{T} \alpha_t \\ 0 & \text{otherwise} \end{cases}

where αt=log⁡(1/βt)\alpha_t = \log (1/\beta_t).

The weight update is clearer with numbers. Suppose the feature picked in the first round has error ϵ1=0.1\epsilon_1 = 0.1 (the paper says the features picked early have errors between 0.1 and 0.3); then β1=0.1/0.9=1/9\beta_1 = 0.1 / 0.9 = 1/9.

The correctly classified samples held 0.9 of the total weight, and multiplied by 1/9 they hold 0.1. The misclassified samples stay at 0.1. After normalization, each side holds half.

In other words, under the new weights the feature just picked has an error of exactly 0.5, no better than guessing. The next round won't pick it again; it will look for a feature that gets right the samples this one got wrong. Each round patches the holes the previous one left.

The vote weight is α1=ln⁡9≈2.20\alpha_1 = \ln 9 \approx 2.20. Suppose the feature picked in the second round has error 0.2, so α2=ln⁡4≈1.39\alpha_2 = \ln 4 \approx 1.39. The two votes total 3.58, and the threshold is half of that, 1.79:

  • if both say face, 3.58≥1.793.58 \ge 1.79, and it's a face;
  • if only the first says so, 2.20≥1.792.20 \ge 1.79, and it's a face;
  • if only the second says so, 1.39<1.791.39 < 1.79, and it's background.

The more accurate the feature, the louder its voice. (The base of the log doesn't matter, since the threshold is a sum in the same base.)

Each round has to find the best threshold for each of the 160,000 features, and the journal version describes how. Sort all samples by the value of the feature and scan once from smallest to largest, keeping four numbers along the way: the total positive weight T+T^+, the total negative weight T−T^-, and the positive weight S+S^+ and negative weight S−S^- below the current position. With the threshold placed at the current position, the error is

e=min⁡(S++(T−−S−),S−+(T+−S+))\begin{aligned} e = \min\big(&S^+ + (T^- - S^-),\\ &S^- + (T^+ - S^+)\big) \end{aligned}

The first term is the error of "everything below is negative, everything above is positive," the second that of the reverse; taking the smaller one also decides pp. Even so, the journal version's 38-stage detector took weeks to train on a 466 MHz AlphaStation, cut to about a day only after it was later parallelized.

The first two features AdaBoost picks look like this:

Original Figure 3: the top row shows the two features themselves. On the left is a wide black rectangle with a thin white rectangle set into its lower half; on the right is a black rectangle with a white vertical bar in the middle. The bottom row overlays the two features on a 24×24 training face: the black part of the first feature covers both eyes and its white part falls on the cheeks below the eyes; the two black blocks of the second feature cover the two eyes and the white bar between them falls on the bridge of the nose. At the bottom left is the original face with no feature overlaid.
Original Figure 3, Viola and Jones, from PDF page 8 of the MERL technical report TR2004-043 version, scholarly quotation.

The first feature compares the band around the eyes with the cheeks below, relying on the eyes usually being darker than the cheeks. This feature is large relative to the window, so it still registers when the face is a bit off-center or a bit bigger. The second feature compares the two eyes with the bridge of the nose between them; the eyes are darker than the bridge of the nose.

Out of 160,000 features, the algorithm found on its own two rules a person grasps at a glance.

The Attentional Cascade: Most Windows See Only Two Features

The paper says the 200-feature classifier is already "probably faster than any other published system," scanning an image in 0.7 seconds. But as worked out above, its false-positive rate is still about two orders of magnitude short, and adding features makes it slower.

The authors came at it from another angle. If a window is a wall, you don't need 200 features to know it isn't a face; two are enough.

Take the AdaBoost classifier built from the first two features and lower its threshold. AdaBoost's default threshold is set to minimize training error; lowered, it calls more things faces. On a validation set, the paper lowered the threshold until it caught 100% of the faces, at the cost of letting 40% of the background through as well. Seen the other way, 60% of the background windows are thrown out at this stage, at a cost of only about 60 processor instructions per window.

Then many such classifiers are chained together:

An attentional cascade diagram drawn for this note, titled "Attentional cascade: a window is out as soon as any stage says no." At the far left is All windows, 100,000s per image; arrows pass in turn through stage 1 (2 features), stage 2 (10 features), stages 3 and 4 (25 each), stages 5–7 (50 each) and on to stage 38, finally reaching Face. Each stage's arrow to the right is labeled T and its arrow downward F, all pointing to a bar at the bottom that reads "Rejected; later stages are never computed." A note under stage 1 says about 50% of non-faces are out and nearly all faces stay; a note under stage 2 says another 80% are out, leaving about 10% after two stages. The bottom line reads: 38 stages, 6,060 features in all; on MIT+CMU a window computes only 8 features on average.
Drawn for this note from the stage sizes and rejection rates in Sections 5.2 and 5.3 of the journal version.

Each stage is an AdaBoost classifier with its threshold lowered so that it almost never misses a face. If any stage says "no," the window is out on the spot and the later stages aren't computed at all; only a window every stage says "yes" to is a face. The paper calls this an attentional cascade, because it works like focusing the computation's attention on the few suspicious locations.

Why does this achieve a high detection rate and a low false-positive rate at the same time? The journal version writes it as two products. Suppose the cascade has KK stages, and on the samples that pass the earlier stages, stage ii has false-positive rate fif_i and detection rate did_i:

F=∏i=1Kfi,D=∏i=1KdiF = \prod_{i=1}^{K} f_i,\qquad D = \prod_{i=1}^{K} d_i

As long as each stage lets 30% of the background through and catches 99% of the faces, chaining 10 stages gives

D=0.9910≈0.904F=0.310≈5.9×10−6\begin{aligned} D &= 0.99^{10} \approx 0.904\\ F &= 0.3^{10} \approx 5.9 \times 10^{-6} \end{aligned}

The demand on each stage is very loose. A 99% detection rate sounds hard, but with 30% false positives allowed at the same time it is much easier. After multiplying through, the detection rate drops only to about 90%, while the false-positive rate drops by five orders of magnitude.

Put 5.9×10−65.9 \times 10^{-6} back on MIT+CMU's 75 million windows and there are still 443 false positives. The final detector kept adding stages, up to 38, until false positives on the validation set were nearly zero.

Speed can be worked out too. The average number of features computed per window is

N=n1+n2 p1+n3 p1p2+⋯N = n_1 + n_2\, p_1 + n_3\, p_1 p_2 + \cdots

nin_i is the number of features in stage ii and pip_i is the fraction stage ii lets through. Because faces are extremely rare, the pass fraction is nearly equal to that stage's false-positive rate. In the final version in the journal paper, stage 1 has 2 features and throws out about 50% of the background, and stage 2 has 10 features and throws out another 80%. The first two terms come to 2+0.5×10=72 + 0.5 \times 10 = 7 features; after these two stages only 0.5×0.2=10%0.5 \times 0.2 = 10\% of the windows remain, and the cost of all 36 later stages is first multiplied by this 0.1. Measured on MIT+CMU, each window computes 8 features on average, out of 6,060 features in all.

The journal version also ran a clean comparison. On one side is a single 200-feature classifier; on the other, a cascade of ten 20-feature classifiers, with the same total number of features. Their ROC curves nearly overlap, and the cascade is almost 10 times faster.

Each Stage Trains on the Earlier Stages' Mistakes

How is the cascade trained? The journal version writes it as a double loop. The user first decides the maximum false-positive rate ff allowed per stage, the minimum detection rate dd per stage, and the overall target false-positive rate FtargetF_{target}.

  1. Add a stage and train it with AdaBoost, starting from 1 feature.
  2. Measure the whole cascade's FiF_i and DiD_i on the validation set, and lower this stage's threshold until the detection rate is at least dd times that of the previous stage.
  3. If the false-positive rate hasn't yet dropped to ff times that of the previous stage, add another feature and go back to step 2.
  4. Once this stage meets its targets, run the current cascade over a large batch of images with no faces, collect the windows wrongly judged to be faces, and use them as the negatives for the next stage.
  5. If the overall false-positive rate is still above FtargetF_{target}, go back to step 1.

Step 4 decides what each stage learns. Stage 1's negatives are cut at random from images with no faces, mostly background you can dismiss at a glance, such as sky and walls. The negatives stage 2 sees are all ones stage 1 failed to stop; those stage 10 sees are ones the first 9 stages all misjudged. The later the stage, the more its negatives look like faces; the paper says this pushes each later stage's whole ROC curve down, so the same detection rate has to tolerate more false positives. That is also why the feature counts keep growing further along, from 2, 10, 25 and 50 to an average of nearly 190 over the last 31 stages (this note's estimate).

In later terminology, this procedure is hard negative mining. The journal version also points out a hidden benefit. A single large classifier can take ten thousand to a hundred thousand negatives at most before it becomes impossible to train; the last few stages of a cascade in effect learn from the few thousand hardest windows sifted out of hundreds of millions of background windows.

The final detector looks like this.

  • Positives: 4,916 faces hand-labeled in photos crawled at random from the web, scaled and aligned to 24×24, plus mirror images for 9,832 in all. The journal version adds how they were cropped: the top of the box above the eyebrows, the bottom halfway between the mouth and the chin, then the whole box enlarged by 50%. The authors tried a tighter-cropped 16×16 version, which did slightly worse; they speculate that the 24×24 crop takes in more of the chin, the cheek contours and the hairline.
  • Negatives: 9,544 images manually checked to contain no faces, holding about 350 million sub-windows. The first stage samples from them at random; each later stage collects at most 10,000 false positives of the cascade before it.
  • Structure: 38 stages, the first five with 1, 10, 25, 25 and 50 features, 6,061 in all.

The journal version's numbers differ slightly, with 2 features in the first stage, 6,060 in all and at most 6,000 negatives collected per stage; the cascade figure above uses the journal version's numbers. The authors are also blunt about it. How many features each stage gets was found by trial and error, with manual intervention in the first 7 stages; the final number of stages and the size of each are not critical to the final performance.

Scanning and Merging

At detection time the detector slides over the image, scaling up by 1.25× each time, with the shift Δ\Delta growing with scale; at scale ss it moves [sΔ][s\Delta] pixels ([⋅][\cdot] is rounding). The paper's main results use Δ=1.0\Delta = 1.0; changing it to 1.5 is a good deal faster, with only a slight loss of accuracy.

Around the same face, shifted by a few pixels or scaled up a little, the detector usually still says face, so several boxes pile up on one face. The paper puts overlapping boxes into the same group and outputs one box per group, with each of its four corners averaged over the group.

The paper also tried voting. Three similar detectors were trained, keeping only results at least two of them agree on. The three detectors' errors are highly correlated, so this brought only a small improvement.

Discussion

Results on MIT+CMU

The test data is the MIT+CMU frontal face test set, 130 images with 507 faces. This dataset has no single agreed "score"; each paper reports only the detection rate at some number of false positives, so the authors read their own ROC curve at the false-positive counts each of the others reported, to make comparison easy.

Original Figure 6: ROC curve on the MIT+CMU test set, titled step size = 1.0. The horizontal axis is the number of false positives, from 0 to 200; the vertical axis is the correct detection rate, from 0.65 to 1. The curve starts at about 2 false positives and a detection rate of 0.68, rises to about 0.86 at 20 false positives and about 0.90 at 40, then climbs slowly to about 0.94 near 180 false positives.
Original Figure 6, Viola and Jones, from PDF page 12 of the MERL technical report TR2004-043 version, scholarly quotation.

The horizontal axis is the "number" of false positives over the whole test set; to turn it into a rate, divide by the 75,081,800 windows scanned. The way the curve is drawn also has to do with the cascade. The final stage's threshold is adjusted first; setting it to negative infinity amounts to removing that stage, and pushing the detection and false-positive rates higher still means removing more stages.

The table below gives the detection rate at several false-positive counts.

False positivesVJVJ votingRowley
1076.1%81.1%83.2%
3188.4%89.7%86.0%
5091.4%92.1%–
6592.0%93.1%–
7892.1%93.1%–
9592.9%93.2%89.2%
16793.9%93.7%90.1%

Compiled from Table 2 of the paper. VJ is this paper's 38-stage detector; Rowley gives the results of the various Rowley–Baluja–Kanade versions.

With only 10 false positives allowed, Rowley's 83.2% beats the single detector's 76.1%, and the voting version is still 2 percentage points behind. From 31 false positives up, VJ beats Rowley all the way. Two other systems report only a single point. Schneiderman–Kanade reaches 94.4% at 65 false positives, higher than VJ's 92.0%; Roth–Yang–Ahuja reaches 94.8% at 78 false positives, but on a subset with the 5 images of line-drawn faces removed, which the journal version specifies as 125 images and 483 faces.

So the paper chooses its words with restraint, claiming detection rates "comparable" to the best previous systems. Where this paper wins is speed.

Speed

With a starting scale of 1.25 and Δ=1.5\Delta = 1.5, a 384×288 image takes about 0.067 seconds on a 700 MHz Pentium III, or 15 images per second. That setting gives about 65,000 windows (this note's estimate), roughly 1 microsecond per window on average. The paper says this is about 15 times faster than Rowley–Baluja–Kanade and about 600 times faster than Schneiderman–Kanade.

The authors also ported it to a Compaq iPaq handheld. Its 200 MIPS StrongARM processor has no floating-point unit, and the detector still ran at 2 images per second.

Where It Fails

The conference version says only that this is a detector for frontal, upright faces. The journal version adds a section on failure modes.

  • Angle: the authors observe that it tolerates only about ±15° of in-plane rotation and ±45° of turning toward profile, and becomes unreliable beyond that. The training faces were only roughly aligned, and this bit of tolerance comes from those untidy samples.
  • Backlighting: it often fails when the face is very dark and the background very bright. A nonlinear normalization that leaves out extreme values helps somewhat, but within the integral-image framework the computation goes up sharply.
  • Occlusion: it usually misses faces with the eyes covered and usually still finds faces with the mouth covered. This fits with the first two features both looking at the eyes.

The authors also own up to a theoretical gap. AdaBoost's training and generalization guarantees hold for its original threshold; whether they still hold after each stage's threshold is lowered, the authors say, is unclear.

The Copy in OpenCV

The Viola–Jones most people actually use is OpenCV's implementation with models trained by Rainer Lienhart, which is not the same detector as the paper's.

haarcascade_frontalface_default.xml also uses a 24×24 window, with 25 stages and 2,913 stumps in total, each stump looking at a single feature; the first stage uses 9 features, increasing stage by stage to around two hundred. The other common one, haarcascade_frontalface_alt.xml, uses a 20×20 window and Gentle AdaBoost, with 22 stages and 2,135 features. Lienhart and Maydt extended the features to rectangles tilted at 45° in 2002, and OpenCV's training tool supports them, but both default models use only upright rectangles.

OpenCV's detection pipeline also differs from the paper in two places.

  • It shrinks the image, not the detector. detectMultiScale downscales the image for each scale and keeps the detector at a fixed size. The default scaleFactor=1.1 is denser than the paper's 1.25; at scales below 2 the window moves 2 pixels at a time, and 1 pixel after that (on the downscaled image).
  • Merging takes a vote. Overlapping boxes are clustered and averaged, but a cluster with fewer than minNeighbors boxes (default 3) is thrown away outright. The paper only averages, with no threshold.

So when OpenCV gives too many false positives, the first thing to tune is minNeighbors; when it misses small faces, look at minSize and scaleFactor.

The defaults of the training tool opencv_traincascade are a minimum hit rate of 0.995 per stage, a maximum false-alarm rate of 0.5 and 20 stages. Its documentation cites the products from Section 4.1 of the journal version directly, for an overall hit rate of about 0.99520≈0.9050.995^{20} \approx 0.905 and a false-alarm rate of about 0.520≈9.5×10−70.5^{20} \approx 9.5 \times 10^{-7}. The tool has been disabled since OpenCV 4.0, and the documentation tells users to go back to the 3.4 branch to train.

On photos from the web, it struggles. In 2015 WIDER FACE used OpenCV's Viola–Jones as one of its baselines. WIDER FACE's test set is split into three subsets, Easy, Medium and Hard, graded roughly by face height, with Hard taking in small faces of 11 to 30 pixels; scores are AP, the area under the curve of precision against recall, with a maximum of 1. Viola–Jones's AP on the three subsets is 0.412, 0.333 and 0.137; on small, unoccluded faces 10 to 50 pixels tall it is only 0.040. LearnOpenCV compared several of OpenCV's and Dlib's face detectors in 2018. Its verdict on the Haar cascade listed many false positives, no use at all on profile faces and no use under occlusion either, and it concluded that it was "time to bid farewell to Haar-based face detector."

OpenCV 5.0 was released in June 2026, and CascadeClassifier and the whole set of haarcascade XMLs have moved from the main library to the xobjdetect module of opencv_contrib (merged into the 5.x branch in March 2024). The official 4-to-5 migration guide recommends that new projects switch to FaceDetectorYN in the main module, which is based on a deep network.

Conclusion

Viola–Jones is fast because it lets the background go as early as possible. Across MIT+CMU's 75 million windows, each window computed only 8 to 10 features on average (8 in the journal version, 10 in the conference version), leaving almost all of the 6,000-plus features to the very few face-like locations. The integral image makes each feature a handful of lookups, AdaBoost picks one feature per round, and the cascade trains later stages on the false positives of earlier ones. Detection rates are comparable to the best systems of its time, and speed is more than an order of magnitude higher.

Access gates, kiosks and similar setups, with the camera facing straight on, steady lighting and one frontal face at a time, are exactly the conditions the paper trained for, and haarcascade_frontalface_default.xml still holds up there. Switch to group photos snapped on a phone, with profiles, backlighting and sunglasses over the eyes, and the failure modes the journal version itself lists show up one by one, and switching to a deep-learning detector saves a lot of trouble. When a project upgrades to OpenCV 5, the Haar cascade needs contrib installed separately, and what the main module has ready is FaceDetectorYN.

The cascade idea has outlived the Haar features. MTCNN in 2016 chains three CNNs of different sizes, and the smallest sweeps the image pyramid first to stop most positions, again letting the cheap classifier speak first.