JeVoisBase  1.22
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
Loading...
Searching...
No Matches
FaceDetector Class Reference

Face detection using OpenCV. More...

#include <jevoisbase/Components/FaceDetection/FaceDetector.H>

Inheritance diagram for FaceDetector:
Collaboration diagram for FaceDetector:

Public Member Functions

 FaceDetector (std::string const &instance)
 Constructor, loads the cascade classifiers from disk.
 
 ~FaceDetector ()
 Destructor.
 
void process (cv::Mat const &img, std::vector< cv::Rect > &faces, std::vector< std::vector< cv::Rect > > &eyes, bool detect_eyes=false)
 Process an image, results are held in our data members.
 
- Public Member Functions inherited from jevois::Component
 Component (std::string const &instance)
 
virtual ~Component ()
 
std::shared_ptr< Comp > addSubComponent (std::string const &instance, Args &&...args)
 
void removeSubComponent (std::shared_ptr< Comp > &component)
 
void removeSubComponent (std::string const &instance, bool warnIfNotFound=true)
 
std::shared_ptr< Comp > getSubComponent (std::string const &instance) const
 
bool isTopLevel () const
 
bool initialized () const
 
std::string const & className () const
 
std::string const & instanceName () const
 
std::vector< std::string > setParamVal (std::string const &paramdescriptor, T const &val)
 
void setParamValUnique (std::string const &paramdescriptor, T const &val)
 
std::vector< std::pair< std::string, T > > getParamVal (std::string const &paramdescriptor) const
 
getParamValUnique (std::string const &paramdescriptor) const
 
std::vector< std::string > setParamString (std::string const &paramdescriptor, std::string const &val)
 
void setParamStringUnique (std::string const &paramdescriptor, std::string const &val)
 
std::vector< std::pair< std::string, std::string > > getParamString (std::string const &paramdescriptor) const
 
std::string getParamStringUnique (std::string const &paramdescriptor) const
 
void freezeParam (std::string const &paramdescriptor, bool doit)
 
void freezeAllParams (bool doit)
 
std::string descriptor () const
 
void setParamsFromFile (std::string const &filename)
 
std::istream & setParamsFromStream (std::istream &is, std::string const &absfile)
 
virtual void paramInfo (std::shared_ptr< UserInterface > s, std::map< std::string, std::string > &categs, bool skipFrozen, std::string const &cname="", std::string const &pfx="")
 
void foreachParam (std::function< void(std::string const &compname, ParameterBase *p)> func, std::string const &cname="")
 
std::shared_ptr< DynamicParameter< T > > addDynamicParameter (std::string const &name, std::string const &description, T const &defaultValue, ParameterCategory const &category)
 
std::shared_ptr< DynamicParameter< T > > addDynamicParameter (std::string const &name, std::string const &description, T const &defaultValue, ValidValuesSpec< T > const &validValuesSpec, ParameterCategory const &category)
 
void setDynamicParameterCallback (std::string const &name, std::function< void(T const &)> cb, bool callnow=true)
 
void removeDynamicParameter (std::string const &name, bool throw_if_not_found=true)
 
void setPath (std::string const &path)
 
std::filesystem::path absolutePath (std::filesystem::path const &path="")
 
std::shared_ptr< Comp > addSubComponent (std::string const &instance, Args &&...args)
 
void removeSubComponent (std::shared_ptr< Comp > &component)
 
void removeSubComponent (std::string const &instance, bool warnIfNotFound=true)
 
std::shared_ptr< Comp > getSubComponent (std::string const &instance) const
 
bool isTopLevel () const
 
bool initialized () const
 
std::string const & className () const
 
std::string const & instanceName () const
 
std::vector< std::string > setParamVal (std::string const &paramdescriptor, T const &val)
 
void setParamValUnique (std::string const &paramdescriptor, T const &val)
 
std::vector< std::pair< std::string, T > > getParamVal (std::string const &paramdescriptor) const
 
getParamValUnique (std::string const &paramdescriptor) const
 
std::vector< std::string > setParamString (std::string const &paramdescriptor, std::string const &val)
 
void setParamStringUnique (std::string const &paramdescriptor, std::string const &val)
 
std::vector< std::pair< std::string, std::string > > getParamString (std::string const &paramdescriptor) const
 
std::string getParamStringUnique (std::string const &paramdescriptor) const
 
void freezeParam (std::string const &paramdescriptor, bool doit)
 
void freezeAllParams (bool doit)
 
std::string descriptor () const
 
void setParamsFromFile (std::string const &filename)
 
std::istream & setParamsFromStream (std::istream &is, std::string const &absfile)
 
virtual void paramInfo (std::shared_ptr< UserInterface > s, std::map< std::string, std::string > &categs, bool skipFrozen, std::string const &cname="", std::string const &pfx="")
 
void foreachParam (std::function< void(std::string const &compname, ParameterBase *p)> func, std::string const &cname="")
 
std::shared_ptr< DynamicParameter< T > > addDynamicParameter (std::string const &name, std::string const &description, T const &defaultValue, ParameterCategory const &category)
 
std::shared_ptr< DynamicParameter< T > > addDynamicParameter (std::string const &name, std::string const &description, T const &defaultValue, ValidValuesSpec< T > const &validValuesSpec, ParameterCategory const &category)
 
void setDynamicParameterCallback (std::string const &name, std::function< void(T const &)> cb, bool callnow=true)
 
void removeDynamicParameter (std::string const &name, bool throw_if_not_found=true)
 
void setPath (std::string const &path)
 
std::filesystem::path absolutePath (std::filesystem::path const &path="")
 
- Public Member Functions inherited from jevois::ParameterRegistry
virtual ~ParameterRegistry ()
 

Protected Member Functions

void postInit () override
 
- Protected Member Functions inherited from jevois::Component
virtual void preInit ()
 
virtual void preUninit ()
 
virtual void postUninit ()
 
virtual void preInit ()
 
virtual void preUninit ()
 
virtual void postUninit ()
 
- Protected Member Functions inherited from jevois::ParameterRegistry
void addParameter (ParameterBase *const param)
 
void removeParameter (ParameterBase *const param)
 
void callbackInitCall ()
 

Protected Attributes

std::shared_ptr< cv::CascadeClassifier > itsFaceCascade
 
std::shared_ptr< cv::CascadeClassifier > itsEyesCascade
 

Related Symbols

(Note that these are not member symbols.)

 JEVOIS_DECLARE_PARAMETER (face_cascade, std::string, "File name of the face cascade", JEVOIS_SHARE_PATH "/facedetector/haarcascade_frontalface_alt.xml", ParamCateg)
 Parameter.
 
 JEVOIS_DECLARE_PARAMETER (eye_cascade, std::string, "File name of the eye cascade, or empty to not detect eyes", JEVOIS_SHARE_PATH "/facedetector/haarcascade_eye_tree_eyeglasses.xml", ParamCateg)
 Parameter.
 

Detailed Description

Face detection using OpenCV.

See tutorial at http://docs.opencv.org/trunk/d7/d8b/tutorial_py_face_detection.html

Definition at line 40 of file FaceDetector.H.

Constructor & Destructor Documentation

◆ FaceDetector()

FaceDetector::FaceDetector ( std::string const &  instance)

Constructor, loads the cascade classifiers from disk.

Definition at line 22 of file FaceDetector.C.

◆ ~FaceDetector()

FaceDetector::~FaceDetector ( )

Destructor.

Definition at line 27 of file FaceDetector.C.

Member Function Documentation

◆ postInit()

void FaceDetector::postInit ( )
overrideprotectedvirtual

Reimplemented from jevois::Component.

Definition at line 31 of file FaceDetector.C.

References jevois::Component::absolutePath(), itsEyesCascade, itsFaceCascade, and LFATAL.

◆ process()

void FaceDetector::process ( cv::Mat const &  img,
std::vector< cv::Rect > &  faces,
std::vector< std::vector< cv::Rect > > &  eyes,
bool  detect_eyes = false 
)

Process an image, results are held in our data members.

The given image should be grayscale and with histogram equalized, for example by doing:

// Given a color image in 'frame'
cv::Mat frame_gray;
cv::cvtColor(frame, frame_gray, CV_BGR2GRAY);
cv::equalizeHist(frame_gray, frame_gray);
// Then send frame_gray to FaceDetector::process()

If detect_eyes is true, throws if an eye cascade was not successfully loaded. Even if we do not detect eyes, the eyes vector will be resized to one (possibly empty) vector of eyes per face, so that it is safe to assume that one entry exists in eyes for each entry in faces.

Definition at line 49 of file FaceDetector.C.

References itsEyesCascade, and itsFaceCascade.

Friends And Related Symbol Documentation

◆ JEVOIS_DECLARE_PARAMETER() [1/2]

JEVOIS_DECLARE_PARAMETER ( eye_cascade  ,
std::string  ,
"File name of the eye  cascade,
or empty to not detect eyes"  ,
JEVOIS_SHARE_PATH "/facedetector/haarcascade_eye_tree_eyeglasses.xml"  ,
ParamCateg   
)
related

Parameter.

◆ JEVOIS_DECLARE_PARAMETER() [2/2]

JEVOIS_DECLARE_PARAMETER ( face_cascade  ,
std::string  ,
"File name of the face cascade"  ,
JEVOIS_SHARE_PATH "/facedetector/haarcascade_frontalface_alt.xml"  ,
ParamCateg   
)
related

Parameter.

Member Data Documentation

◆ itsEyesCascade

std::shared_ptr<cv::CascadeClassifier> FaceDetector::itsEyesCascade
protected

Definition at line 69 of file FaceDetector.H.

Referenced by postInit(), and process().

◆ itsFaceCascade

std::shared_ptr<cv::CascadeClassifier> FaceDetector::itsFaceCascade
protected

Definition at line 68 of file FaceDetector.H.

Referenced by postInit(), and process().


The documentation for this class was generated from the following files: