Haar Cascade Model Documentation
Documentation for Haar Cascade models.
See OpenCV documentation for more information here.
Scale, neighbors and size are also explained documentation here.
detect_face_haar(img, detector, detect_multiple_faces=True, scale=1.1, neighbors=10, size=50)
Function for detecting faces in an image using a pre-trained Haar Cascade model provided by OpenCV.
This project uses the "haarcascade_frontalface_default.xml" model, but the function allows for other cascade classifier.
Default values for scaling, neighbors and size of the window are set. By default the detector will detect multiple faces. Set detect_multiple_faces
to false for detecting one face.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img |
ndarray
|
The image in which faces are to be detected, typically obtained from |
required |
detector |
CascadeClassifier
|
An instance of Haar Cascade detector, pre-trained for face detection. |
required |
detect_multiple_faces |
bool
|
Controls whether to detect multiple faces or just the most prominent one. Defaults to True, detecting multiple faces. |
True
|
scale |
float
|
The factor by which the image is scaled down to facilitate detection. Scaling down the image can lead to faster detection with less precision. Defaults to 1.1 (10% reduction). |
1.1
|
neighbors |
int
|
The number of neighbors each candidate rectangle should have to retain it. A higher number gives fewer detections but with higher quality. Defaults to 10. |
10
|
size |
int
|
The minimum size of faces to detect, specified as the side length of the square sliding window used in detection. Defaults to 50 pixels. |
50
|
Returns:
Type | Description |
---|---|
list | tuple | None
|
If |
Source code in src/models/code/haar.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|