Haar Face Detection

The Haar classifier is based on the Haar-like features proposed by Viola and Jones. These features are simple rectangular filters that capture specific patterns in an image, such as edges, lines, and corners. The classifier works by applying a series of these Haar-like features to sub-regions of an image and evaluating the response at each stage to determine the likelihood of a face being present. The Haar classifier consists of a cascade of weak classifiers, which are trained using a variant of the AdaBoost algorithm. Evaluated on Labeled Faces in the Wild (LFW) dataset, the classifier has demonstrated impressive results, achieving accuracies of over 95% with low false-positive rates.

Example

from dronevis.models import HaarFaceDetection

model = HaarFaceDetection() # create model instance
model.load()                # load model weights
model.detect_webcam()       # run camera detection

Haar Face Detection Class

class dronevis.models.HaarFaceDetection(min_neighbours=5, min_size=(10, 10), scale_factor=1.1)

Face detection class with Haar Cascades

Paper: Rapid Object Detection using a Boosted Cascade of Simple Features

__init__(min_neighbours=5, min_size=(10, 10), scale_factor=1.1)

Initialize model instance

Parameters
  • min_neighbours (int, optional) – Number of neighbours each candidate. Defaults to 5.

  • min_size (Tuple[int, int], optional) – Min box size for each face. Defaults to (10, 10).

  • scale_factor (float, optional) – Scale the image. Defaults to 1.1.

load_model(model_name=None)

Laod model weights

transform_img(image)

Run image transformation

predict(image)

Run model inference on the image

Parameters

image (np.ndarray) – Input image

Returns

Image withe face annotations

Return type

np.ndarray

detect_webcam(video_index=0, window_name='Haar Face')

Run model on a video stream from the webcam

Parameters
  • video_index (int) – Index of the camera/video device to retrieve stream

  • window_name (str, optional) – Name of openCV window for running the mpdel.

  • to "Cam Detection". (Defaults) –