Hi all, Hope you all are doing all. Today I will explain the face detection procedure used in opencv.
Step1: create cascaded classifier using the training algorithm provided by opencv and get the .xml file.
Step2: load the pre-made .xml file.
Step3: input frame from camera/ input image and convert it to grey scale image.
Step4: use opencv’s ‘CascadeClassifier:: detectMultiScale()’ function to detect faces of different sizes in the input image.
Explanation of CascadeClassifier::detectMultiScale() –
- image- Matrix of the type CV_8U containing an image where objects are detected.
- objects– Vector of rectangles where each rectangle contains the detected object.
iii. scaleFactor – Parameter specifying how much the image size is reduced at each image scale.
- minNeighbors– Parameter specifying how many neighbour’s each candidate rectangle should have to retain it.
- minSize– Minimum possible object size. Objects smaller than that are ignored.
- maxSize– Maximum possible object size. Objects larger than that are ignored.
- Basically what ‘CascadeClassifier:: detectMultiScale()’ does is it takes the original image and creates an image pyramid from it, using the resize factor and searches for faces/objects in it. Image pyramid is a multi-scale representation of an image, such that the face detection can be scale-invariant, i.e., detecting large and small faces using the same detection window.
- This gives the ability of detecting faces/objects at a single model scale, throughout different images scales, meaning that if a detection happens at a specific layer, the bounding box will be rescaled the same amount as the original image was to reach that pyramid layer.
- Using this technique you can detect multiple people scales at only a single model scale, which is computationally less expensive than training a model for each possible scale and running those over the single image.
- To make a good detector you need to train the cascade properly with a good number of sample images. Here is an example-