/*
  FaceDetector.h
  
  Author: Sergi Diaz Planas (2017)
*/
#ifndef FACEDETECTOR_H
#define FACEDETECTOR_H

/* Class responsible for face and features detection.
 * Face detection is performed by OpenCV's cascade classifier,
 * using haar features provided by them. Features detection and
 * positioning is performed by dlib's shape predictor.
 *
 * */

#include "opencv2/objdetect.hpp"
#include "dlib/image_processing.h"
#include "Face.h"

#include <phpcpp.h>

using namespace dlib;
using namespace cv;

class FaceDetector
{
public:
    FaceDetector();
    FaceDetector(std::string classifierFile,
                 std::string predictorFile);
    bool loadClassifier(std::string file);
    bool loadShapePredictor(std::string file);
    bool isLoaded();
    Face getFace(Image image);

private:
    std::vector<Rect> getRectFaces(Mat image);
    full_object_detection getFacialFeatures(Mat cvImage, Rect cvDet);
    dlib::array2d<unsigned char> getFaceChip(Mat cvImage, full_object_detection feat);

    CascadeClassifier classifier;
    shape_predictor shapePredictor;

    bool classifierLoaded;
    bool predictorLoaded;

};

#endif // FACEDETECTOR_H
