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
Default constructor.
Overloaded function.
Set the name of the OpenCV cascade classifier file used for face detection.
Inherited Methods
Return the center of gravity location of the ith object.
Overloaded function.
Return the bounding box of the ith object.
Return the number of objects that are detected.
Overloaded function.
Set detector timeout in milli-seconds.
Operators
__doc__
Default constructor.
__module__
Attributes
__annotations__
- __init__(self)¶
Default constructor.
- detect(*args, **kwargs)¶
Overloaded function.
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.
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.
getMessage(self: visp._visp.detection.DetectorBase) -> list[str]
Returns the contained message of the ith object if there is one.
getMessage(self: visp._visp.detection.DetectorBase, i: int) -> str
Returns the contained message of the ith object if there is one.
- getPolygon(*args, **kwargs)¶
Overloaded function.
getPolygon(self: visp._visp.detection.DetectorBase) -> list[list[visp._visp.core.ImagePoint]]
Returns object container box as a vector of points.
getPolygon(self: visp._visp.detection.DetectorBase, i: int) -> list[visp._visp.core.ImagePoint]
Returns ith object container box as a vector of points.