DetectorFace

class DetectorFace(self)

Bases: DetectorBase

The vpDetectorFace class is a wrapper over OpenCV Haar cascade face detection capabilities. To use this class ViSP should be build against OpenCV 2.2.0 or a more recent version. Installation instructions are provided here https://visp.inria.fr/3rd_opencv .

The following sample code shows how to use this class to detect the largest face in the image. The cascade classifier file “haarcascade_frontalface_alt.xml” can be found in ViSP source code or in OpenCV.

#include <visp3/detection/vpDetectorFace.h>

int main()
{
#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_OBJDETECT)
  vpImage<unsigned char> I;
  vpDetectorFace face_detector;
  face_detector.setCascadeClassifierFile("haarcascade_frontalface_alt.xml");

  while(1) {
    // Acquire a new image in I
    bool face_found = face_detector.detect(I);
    if (face_found) {
      vpRect face_bbox = face_detector.getBBox(0); // largest face has index 0
    }
  }
#endif
}

A more complete example that works with images acquired from a camera is provided in tutorial-face-detector-live.cpp.

Default constructor.

Methods

__init__

Default constructor.

detect

Overloaded function.

setCascadeClassifierFile

Set the name of the OpenCV cascade classifier file used for face detection.

Inherited Methods

getCog

Return the center of gravity location of the ith object.

getPolygon

Overloaded function.

getBBox

Return the bounding box of the ith object.

getNbObjects

Return the number of objects that are detected.

getMessage

Overloaded function.

setTimeout

Set detector timeout in milli-seconds.

Operators

__doc__

__init__

Default constructor.

__module__

Attributes

__annotations__

__init__(self)

Default constructor.

detect(*args, **kwargs)

Overloaded function.

  1. detect(self: visp._visp.detection.DetectorFace, I: visp._visp.core.ImageGray) -> bool

Allows to detect a face in the image. When more than one face is detected, faces are sorted from largest to smallest.

The number of detected faces is returned using getNbObjects() . If a face is found the functions getBBox() , getCog() return some information about the location of the face.

The largest face is always available using getBBox(0) or getCog(0).

Note

See detect(const cv::Mat &)

Parameters:
I

Input image to process. This ViSP image is converted internally in an OpenCV cv::Mat image. If you original image is an gray level OpenCV image, we suggest rather the use of detect(const cv::Mat &) .

Returns:

true if one or more faces are found, false otherwise.

  1. detect(self: visp._visp.detection.DetectorFace, frame_gray: cv::Mat) -> bool

Allows to detect a face in the image. When more than one face is detected, faces are sorted from largest to smallest.

The number of detected faces is returned using getNbObjects() . If a face is found the functions getBBox() , getCog() return some information about the location of the face.

The largest face is always available using getBBox(0) or getCog(0).

Parameters:
frame_gray

Input gray level image to process.

Returns:

true if one or more faces are found, false otherwise.

getBBox(self, i: int) visp._visp.core.Rect

Return the bounding box of the ith object.

getCog(self, i: int) visp._visp.core.ImagePoint

Return the center of gravity location of the ith object.

getMessage(*args, **kwargs)

Overloaded function.

  1. getMessage(self: visp._visp.detection.DetectorBase) -> list[str]

Returns the contained message of the ith object if there is one.

  1. getMessage(self: visp._visp.detection.DetectorBase, i: int) -> str

Returns the contained message of the ith object if there is one.

getNbObjects(self) int

Return the number of objects that are detected.

getPolygon(*args, **kwargs)

Overloaded function.

  1. getPolygon(self: visp._visp.detection.DetectorBase) -> list[list[visp._visp.core.ImagePoint]]

Returns object container box as a vector of points.

  1. getPolygon(self: visp._visp.detection.DetectorBase, i: int) -> list[visp._visp.core.ImagePoint]

Returns ith object container box as a vector of points.

setCascadeClassifierFile(self, filename: str) None

Set the name of the OpenCV cascade classifier file used for face detection.

Parameters:
filename: str

Full path to access to the file. Such a file can be found in OpenCV. Within the last versions it was name “haarcascade_frontalface_alt.xml”.

setTimeout(self, timeout_ms: int) None

Set detector timeout in milli-seconds. When set to 0, there is no timeout.