annotations.FaceDetection package

Submodules

annotations.FaceDetection.imgfacedetect module

filename

sppas.src.annotations.FaceDetection.imgfacedetect.py

author

Brigitte Bigi

contact

develop@sppas.org

summary

Automatic detection of faces in an image.

class annotations.FaceDetection.imgfacedetect.ImageFaceDetection[source]

Bases: sppas.src.imgdata.sppasImageObjectDetection

Detect faces in an image.

Automatic face detection, based on opencv HaarCascadeClassifier and Artificial Neural Networks: this class allows to analyze an image in order to detect all faces. It stores internally the list of sppasCoords() for each detected face.

Like the base class, this class allows multiple models in order to launch multiple detections and to combine results. Moreover, it allows to convert the coordinates into the portrait instead of the face.

Example
>>> f = ImageFaceDetection()
>>> f.load_model(filename1, filename2...)
>>> # Detect all the faces in an image
>>> image = sppasImage(filename="image path"))
>>> f.detect(image)
>>> # Get number of detected faces
>>> len(f)
>>> # Browse through all the detected face coordinates:
>>> for c in f:
>>>     print(c)
>>> # Get the detected faces with the highest score
>>> f.get_best()
>>> # Get the 2 faces with the highest scores
>>> f.get_best(2)
>>> # Get detected faces with a confidence score greater than 0.8
>>> f.get_confidence(0.8)
>>> # Convert coordinates to a portrait size (i.e. scale by 2.1)
>>> f.to_portrait(image)
__init__()[source]

Create a new instance.

detect(image)[source]

Determine the coordinates of all the detected faces.

Parameters

image – (sppasImage or numpy.ndarray)

static eval_portrait(coordinate, image=None)[source]

Return the coordinates converted to the portrait scale.

Parameters
  • coordinate – (sppasCoords)

  • image – (sppasImage) The original image.

Returns

(sppasCoords)

to_portrait(image=None)[source]

Scale coordinates of faces to a portrait size.

The given image allows to ensure we wont scale larger than what the image can do.

Parameters

image – (sppasImage) The original image.

annotations.FaceDetection.sppasfacedetect module

filename

sppas.src.annotations.FaceDetection.sppasfacedetect.py

author

Brigitte Bigi

contact

develop@sppas.org

summary

SPPAS integration of the Face detection automatic annotation.

class annotations.FaceDetection.sppasfacedetect.sppasFaceDetection(log=None)[source]

Bases: annotations.baseannot.sppasBaseAnnotation

SPPAS integration of the automatic face detection systems.

Can detect faces in an image or in all images of a video.

For this annotation, the user can’t change the output pattern; it is intentional. The pattern is either ‘-face’ or ‘-portrait’ if the option portrait is enabled.

__init__(log=None)[source]

Create a new automatic annotation instance.

Parameters

log – (sppasLog) Human-readable logs.

Raise

sppasEnableFeatureError

fix_options(options)[source]

Fix all options.

Parameters

options – (sppasOption)

static get_input_extensions()[source]

Extensions that the annotation expects for its input filename.

Priority is given to video files, then image files.

get_inputs(input_files)[source]

Return the media filenames.

Parameters

input_files – (list)

Raise

NoInputError

Returns

(str) Name of the media file

get_output_pattern()[source]

Pattern this annotation uses in an output filename.

image_face_detect(image, output=None)[source]

Get the image, detect faces and write results.

Parameters
  • image – (str) Image filename

  • output – (str) The output name for the image

Returns

(list) the coordinates of all detected faces or created filenames

load_resources(model1, *args, **kwargs)[source]

Fix the model files.

Currently, both HaarCascade classifiers and DNN are supported. Add as many models as wished; their results are combined.

Parameters
  • model1 – (str) Filename of a model

  • args – other models for face detection

run(input_files, output=None)[source]

Run the automatic annotation process on a single input.

Parameters
  • input_files – (list of str) Video or image file

  • output – (str) the output name

Returns

(list of sppasCoords) Coordinates of detected faces or filenames

set_img_crop(value=True)[source]

Create an image/video for each detected person.

Parameters

value – (bool) Crop the images

set_img_height(value)[source]

Height of the resulting images/video.

Parameters

value – (int) Number of pixel

set_img_portrait(value)[source]

Result is the portrait instead of the face.

Parameters

value – (bool) True

set_img_tag(value=True)[source]

Surround the faces with a square.

Parameters

value – (bool) Tag the images

set_img_width(value)[source]

Width of the resulting images/video.

Parameters

value – (int) Number of pixels

set_max_faces(value)[source]

Fix the maximum number of expected faces in an image.

Parameters

value – (int) Number of faces

set_min_score(value)[source]

Fix the minimum score to accept a face in an image.

Parameters

value – (float) Min confidence score of face detection result

set_out_csv(out_csv=False)[source]

The result includes a CSV file.

Parameters

out_csv – (bool) Create a CSV file when detecting

set_out_folder(out_folder=False)[source]

The result includes a folder with image files – if video input.

Parameters

out_folder – (bool) Create a folder with image files when detecting

annotations.FaceDetection.videofacedetect module

filename

sppas.src.annotations.FaceDetection.videofacedetect.py

author

Brigitte Bigi

contact

develop@sppas.org

summary

Automatic detection of faces in a video.

class annotations.FaceDetection.videofacedetect.VideoFaceDetection(face_detection)[source]

Bases: object

Search for faces on all images of a video.

__init__(face_detection)[source]

Create a new instance.

Parameters

face_detection – (ImageFaceDetection) FD image system

detect_buffer()[source]

Search for faces in the currently loaded buffer of the video.

Determine the coordinates of all the detected faces of all images. They are ranked from the highest score to the lowest one.

Raise

sppasError if no model was loaded.

get_filter_best()[source]

Return the max nb of faces to detect.

get_filter_confidence()[source]

Return the min scores of faces to detect.

set_filter_best(value=- 1)[source]

Force to detect at max the given number of faces.

Parameters

value – (int) Number of faces to detect or -1 to not force.

set_filter_confidence(value=0.2)[source]

Force to detect only the faces with a confidence score > value.

It means that any detected face with a score lesser than the given one will be ignored. The score of detected faces are supposed to range between 0. and 1.

Parameters

value – (float) Value ranging [0., 1.]

Raise

ValueError

set_portrait(value=True)[source]

Consider the portrait instead of the face.

Parameters

value – (bool)

video_face_detect(video, video_writer=None, output=None)[source]

Browse the video, detect faces and write results.

Parameters
  • video – (str) Video filename

  • video_writer – ()

  • output – (str) The output name for the folder and/or the video

Returns

(list) The coordinates of all detected faces on all images

Module contents

filename

sppas.src.annotations.FaceDetection.__init__.py

author

Brigitte Bigi

contact

develop@sppas.org

summary

Automatic detection of faces with opencv.

This package requires video feature, for opencv and numpy dependencies.

class annotations.FaceDetection.ImageFaceDetection[source]

Bases: object

__init__()[source]
class annotations.FaceDetection.VideoFaceDetection[source]

Bases: object

__init__()[source]
class annotations.FaceDetection.sppasFaceDetection(*args, **kwargs)[source]

Bases: object

__init__(*args, **kwargs)[source]