We can use the resize() function to shrink an image to a certain size or scale factor. Face detection usually works quite well for any image size greater than 240 x 240 pixels (unless you need to detect faces that are far away from the camera), because it will look for any faces larger than the minFeatureSize (typically 20 x 20 pixels). So let's shrink the camera image to be 320 pixels wide; it doesn't matter if the input is a VGA webcam or a 5 mega pixel HD camera. It is also important to remember and enlarge the detection results, because if you detect faces in a shrunk image then the results will also be shrunk. Note that instead of shrinking the input image, you could use a large minFeatureSize value in the detector instead. We must also ensure
the image does not become fatter or thinner. For example, a widescreen 800 x 400 image when shrunk to 300 x 200 would make a person look thin. So we must keep the aspect ratio (the ratio of width to height) of the output same as the input. Let's calculate how much to shrink the image width by, then apply the same scale factor to the height as well, as follows: