Visual Servoing Platform
version 3.6.1 under development (2024-11-21)
|
#include <visp3/detection/vpDetectorFace.h>
Public Member Functions | |
vpDetectorFace () | |
bool | detect (const vpImage< unsigned char > &I) VP_OVERRIDE |
bool | detect (const cv::Mat &frame_gray) |
void | setCascadeClassifierFile (const std::string &filename) |
Protected Attributes | |
std::vector< cv::Rect > | m_faces |
cv::CascadeClassifier | m_face_cascade |
cv::Mat | m_frame_gray |
Inherited functionalities from vpDetectorBase | |
std::vector< std::vector< vpImagePoint > > | m_polygon |
std::vector< std::string > | m_message |
size_t | m_nb_objects |
unsigned long | m_timeout_ms |
vpRect | getBBox (size_t i) const |
vpImagePoint | getCog (size_t i) const |
std::vector< std::string > & | getMessage () |
std::string & | getMessage (size_t i) |
size_t | getNbObjects () const |
std::vector< std::vector< vpImagePoint > > & | getPolygon () |
std::vector< vpImagePoint > & | getPolygon (size_t i) |
void | setTimeout (unsigned long timeout_ms) |
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.
A more complete example that works with images acquired from a camera is provided in tutorial-face-detector-live.cpp.
Definition at line 90 of file vpDetectorFace.h.
BEGIN_VISP_NAMESPACE vpDetectorFace::vpDetectorFace | ( | ) |
Default constructor.
Definition at line 50 of file vpDetectorFace.cpp.
bool vpDetectorFace::detect | ( | const cv::Mat & | frame_gray | ) |
Allows to detect a face in the image. When more than one face is detected, faces are sorted from largest to smallest.
frame_gray | : Input gray level image to process. |
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).
Definition at line 101 of file vpDetectorFace.cpp.
References m_face_cascade, m_faces, vpDetectorBase::m_message, vpDetectorBase::m_nb_objects, and vpDetectorBase::m_polygon.
|
virtual |
Allows to detect a face in the image. When more than one face is detected, faces are sorted from largest to smallest.
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 &). |
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).
Implements vpDetectorBase.
Definition at line 82 of file vpDetectorFace.cpp.
References vpImageConvert::convert(), and m_frame_gray.
|
inherited |
Return the bounding box of the ith object.
Definition at line 93 of file vpDetectorBase.cpp.
References vpDetectorBase::m_polygon.
|
inherited |
Return the center of gravity location of the ith object.
Definition at line 79 of file vpDetectorBase.cpp.
References vpDetectorBase::m_polygon.
|
inlineinherited |
Returns the contained message of the ith object if there is one.
Definition at line 98 of file vpDetectorBase.h.
|
inherited |
Returns the contained message of the ith object if there is one.
Definition at line 65 of file vpDetectorBase.cpp.
References vpException::badValue, vpDetectorBase::m_message, and vpDetectorBase::m_polygon.
|
inlineinherited |
Return the number of objects that are detected.
Definition at line 108 of file vpDetectorBase.h.
|
inlineinherited |
Returns object container box as a vector of points.
Definition at line 113 of file vpDetectorBase.h.
|
inherited |
Returns ith object container box as a vector of points.
Definition at line 51 of file vpDetectorBase.cpp.
References vpException::badValue, and vpDetectorBase::m_polygon.
void vpDetectorFace::setCascadeClassifierFile | ( | const std::string & | filename | ) |
Set the name of the OpenCV cascade classifier file used for face detection.
filename | : 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". |
Definition at line 58 of file vpDetectorFace.cpp.
References vpException::ioError, and m_face_cascade.
|
inlineinherited |
Set detector timeout in milli-seconds. When set to 0, there is no timeout.
Definition at line 123 of file vpDetectorBase.h.
Referenced by vpDetectorDataMatrixCode::vpDetectorDataMatrixCode().
|
protected |
Haar cascade classifier file name.
Definition at line 94 of file vpDetectorFace.h.
Referenced by detect(), and setCascadeClassifierFile().
|
protected |
Bounding box of each detected face.
Definition at line 93 of file vpDetectorFace.h.
Referenced by detect().
|
protected |
OpenCV image used as input for the face detection.
Definition at line 95 of file vpDetectorFace.h.
Referenced by detect().
|
protectedinherited |
Message attached to each object.
Definition at line 129 of file vpDetectorBase.h.
Referenced by detect(), vpDetectorAprilTag::detect(), vpDetectorDataMatrixCode::detect(), and vpDetectorBase::getMessage().
|
protectedinherited |
Number of detected objects.
Definition at line 130 of file vpDetectorBase.h.
Referenced by detect(), vpDetectorAprilTag::detect(), and vpDetectorDataMatrixCode::detect().
|
protectedinherited |
For each object, defines the polygon that contains the object.
Definition at line 128 of file vpDetectorBase.h.
Referenced by detect(), vpDetectorAprilTag::detect(), vpDetectorDataMatrixCode::detect(), vpDetectorBase::getBBox(), vpDetectorBase::getCog(), vpDetectorBase::getMessage(), vpDetectorBase::getPolygon(), and vpDetectorAprilTag::getTagsCorners().
|
protectedinherited |
Detection timeout.
Definition at line 131 of file vpDetectorBase.h.
Referenced by vpDetectorDataMatrixCode::detect().