ViSP  2.10.0
vpDetectorFace Class Reference

#include <vpDetectorFace.h>

+ Inheritance diagram for vpDetectorFace:

Public Member Functions

 vpDetectorFace ()
 
virtual ~vpDetectorFace ()
 
void setCascadeClassifierFile (const std::string &filename)
 
bool detect (const vpImage< unsigned char > &I)
 
std::vector< std::vector< vpImagePoint > > & getPolygon ()
 
std::vector< vpImagePoint > & getPolygon (size_t i)
 
std::string & getMessage (size_t i)
 
std::vector< std::string > & getMessage ()
 
size_t getNbObjects () const
 
vpImagePoint getCog (size_t i) const
 
vpRect getBBox (size_t i) const
 

Protected Attributes

std::vector< cv::Rect > m_faces
 
cv::CascadeClassifier m_face_cascade
 
cv::Mat m_frame_gray
 
std::vector< std::vector< vpImagePoint > > m_polygon
 
std::vector< std::string > m_message
 
size_t m_nb_objects
 

Detailed Description

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.

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 <visp/vpDetectorFace.h>
int main()
{
vpDetectorFace face_detector;
face_detector.setCascadeClassifierFile("haarcascade_frontalface_alt.xml");
while(1) {
// acquire a new image in I
bool face_found = face_detector.track(I);
if (face_found) {
vpRect face_bbox = face_detector.getBoundingBox(0); // largest face has index 0
}
}
}

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

Examples:
tutorial-face-detector-live.cpp, and tutorial-face-detector.cpp.

Definition at line 81 of file vpDetectorFace.h.

Constructor & Destructor Documentation

vpDetectorFace::vpDetectorFace ( )

Default constructor.

Definition at line 55 of file vpDetectorFace.cpp.

virtual vpDetectorFace::~vpDetectorFace ( )
inlinevirtual

Default destructor.

Definition at line 93 of file vpDetectorFace.h.

Member Function Documentation

bool vpDetectorFace::detect ( const vpImage< unsigned char > &  I)
virtual

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

Parameters
I: Input image to process.
Returns
true if one or more faces are found, false otherwise.

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.

Examples:
tutorial-face-detector-live.cpp, and tutorial-face-detector.cpp.

Definition at line 83 of file vpDetectorFace.cpp.

References vpImageConvert::convert(), m_face_cascade, m_faces, m_frame_gray, vpDetectorBase::m_message, vpDetectorBase::m_nb_objects, and vpDetectorBase::m_polygon.

vpRect vpDetectorBase::getBBox ( size_t  i) const
inlineinherited

Return the bounding box of the ith object.

Examples:
tutorial-barcode-detector-live.cpp, tutorial-barcode-detector.cpp, tutorial-face-detector-live.cpp, and tutorial-face-detector.cpp.

Definition at line 141 of file vpDetectorBase.h.

vpImagePoint vpDetectorBase::getCog ( size_t  i) const
inlineinherited

Return the center of gravity location of the ith object.

Definition at line 129 of file vpDetectorBase.h.

std::string& vpDetectorBase::getMessage ( size_t  i)
inlineinherited

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

Examples:
tutorial-barcode-detector-live.cpp, tutorial-barcode-detector.cpp, tutorial-face-detector-live.cpp, and tutorial-face-detector.cpp.

Definition at line 108 of file vpDetectorBase.h.

References vpException::badValue.

std::vector< std::string >& vpDetectorBase::getMessage ( )
inlineinherited

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

Definition at line 118 of file vpDetectorBase.h.

size_t vpDetectorBase::getNbObjects ( ) const
inlineinherited

Return the number of objects that are detected.

Examples:
tutorial-barcode-detector-live.cpp, tutorial-barcode-detector.cpp, tutorial-face-detector-live.cpp, and tutorial-face-detector.cpp.

Definition at line 125 of file vpDetectorBase.h.

std::vector< std::vector<vpImagePoint> >& vpDetectorBase::getPolygon ( )
inlineinherited

Returns object container box as a vector of points.

Examples:
tutorial-barcode-detector-live.cpp, tutorial-barcode-detector.cpp, tutorial-face-detector-live.cpp, and tutorial-face-detector.cpp.

Definition at line 90 of file vpDetectorBase.h.

std::vector<vpImagePoint>& vpDetectorBase::getPolygon ( size_t  i)
inlineinherited

Returns ith object container box as a vector of points.

Definition at line 98 of file vpDetectorBase.h.

References vpException::badValue.

void vpDetectorFace::setCascadeClassifierFile ( const std::string &  filename)

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

Parameters
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".
Examples:
tutorial-face-detector-live.cpp, and tutorial-face-detector.cpp.

Definition at line 65 of file vpDetectorFace.cpp.

References vpException::ioError, and m_face_cascade.

Member Data Documentation

cv::CascadeClassifier vpDetectorFace::m_face_cascade
protected

Haar cascade classifier file name.

Definition at line 85 of file vpDetectorFace.h.

Referenced by detect(), and setCascadeClassifierFile().

std::vector<cv::Rect> vpDetectorFace::m_faces
protected

Bounding box of each detected face.

Definition at line 84 of file vpDetectorFace.h.

Referenced by detect().

cv::Mat vpDetectorFace::m_frame_gray
protected

OpenCV image used as input for the face detection.

Definition at line 86 of file vpDetectorFace.h.

Referenced by detect().

std::vector< std::string > vpDetectorBase::m_message
protectedinherited

Message attached to each object.

Definition at line 68 of file vpDetectorBase.h.

Referenced by detect(), vpDetectorDataMatrixCode::detect(), and vpDetectorQRCode::detect().

size_t vpDetectorBase::m_nb_objects
protectedinherited

Number of detected objects.

Definition at line 69 of file vpDetectorBase.h.

Referenced by detect(), vpDetectorDataMatrixCode::detect(), and vpDetectorQRCode::detect().

std::vector< std::vector<vpImagePoint> > vpDetectorBase::m_polygon
protectedinherited

For each object, defines the polygon that contains the object.

Definition at line 67 of file vpDetectorBase.h.

Referenced by detect(), vpDetectorDataMatrixCode::detect(), and vpDetectorQRCode::detect().