JeVoisBase  1.20
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
FaceDetector.H
Go to the documentation of this file.
1 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2016 by Laurent Itti, the University of Southern
4 // California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5 //
6 // This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7 // redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8 // Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10 // License for more details. You should have received a copy of the GNU General Public License along with this program;
11 // if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 //
13 // Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14 // Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16 /*! \file */
17 
18 #pragma once
19 
21 
22 #include <opencv2/objdetect/objdetect.hpp>
23 
24 namespace facedetector
25 {
26  static jevois::ParameterCategory const ParamCateg("FaceDetector Options");
27 
28  //! Parameter \relates FaceDetector
29  JEVOIS_DECLARE_PARAMETER(face_cascade, std::string, "File name of the face cascade",
30  JEVOIS_SHARE_PATH "/facedetector/haarcascade_frontalface_alt.xml", ParamCateg);
31 
32  //! Parameter \relates FaceDetector
33  JEVOIS_DECLARE_PARAMETER(eye_cascade, std::string, "File name of the eye cascade, or empty to not detect eyes",
34  JEVOIS_SHARE_PATH "/facedetector/haarcascade_eye_tree_eyeglasses.xml", ParamCateg);
35 }
36 
37 //! Face detection using OpenCV
38 /*! See tutorial at http://docs.opencv.org/trunk/d7/d8b/tutorial_py_face_detection.html
39  \ingroup components */
41  public jevois::Parameter<facedetector::face_cascade, facedetector::eye_cascade>
42 {
43  public:
44  //! Constructor, loads the cascade classifiers from disk
45  FaceDetector(std::string const & instance);
46 
47  //! Destructor
48  ~FaceDetector();
49 
50  //! Process an image, results are held in our data members
51  /*! The given image should be grayscale and with histogram equalized, for example by doing:
52  \code
53  // Given a color image in 'frame'
54  cv::Mat frame_gray;
55  cv::cvtColor(frame, frame_gray, CV_BGR2GRAY);
56  cv::equalizeHist(frame_gray, frame_gray);
57  // Then send frame_gray to FaceDetector::process()
58  \endcode
59 
60  If detect_eyes is true, throws if an eye cascade was not successfully loaded. Even if we do not detect eyes, the
61  eyes vector will be resized to one (possibly empty) vector of eyes per face, so that it is safe to assume that
62  one entry exists in eyes for each entry in faces. */
63  void process(cv::Mat const & img, std::vector<cv::Rect> & faces, std::vector<std::vector<cv::Rect> > & eyes,
64  bool detect_eyes = false);
65 
66  protected:
67  void postInit() override;
68  std::shared_ptr<cv::CascadeClassifier> itsFaceCascade;
69  std::shared_ptr<cv::CascadeClassifier> itsEyesCascade;
70 };
FaceDetector::~FaceDetector
~FaceDetector()
Destructor.
Definition: FaceDetector.C:27
FaceDetector
Face detection using OpenCV.
Definition: FaceDetector.H:40
JEVOIS_DECLARE_PARAMETER
JEVOIS_DECLARE_PARAMETER(thresh1, double, "First threshold for hysteresis", 50.0, ParamCateg)
jevois::Component
jevois::ParameterCategory
Component.H
FaceDetector::process
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.
Definition: FaceDetector.C:49
FaceDetector::FaceDetector
FaceDetector(std::string const &instance)
Constructor, loads the cascade classifiers from disk.
Definition: FaceDetector.C:22
FaceDetector::itsEyesCascade
std::shared_ptr< cv::CascadeClassifier > itsEyesCascade
Definition: FaceDetector.H:69
facedetector
Definition: FaceDetector.H:24
FaceDetector::postInit
void postInit() override
Definition: FaceDetector.C:31
FaceDetector::itsFaceCascade
std::shared_ptr< cv::CascadeClassifier > itsFaceCascade
Definition: FaceDetector.H:68