#ifndef MYFACEDETECTOR_H_
#define MYFACEDETECTOR_H_

#include <vector>

#include <FCam/Base.h>

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/objdetect/objdetect.hpp>

#define PREVIEW_IMAGE_WIDTH  640
#define PREVIEW_IMAGE_HEIGHT 480

class MyFaceDetector {
public:
	MyFaceDetector(const char* filename) : classifier(filename) {
		acquire = false;
		minNeighbors = 3; // Default from OpenCV
	}
	std::vector<cv::Rect> detectFace(const FCam::Image& im) {
		/* [CS478]
		 * You will need to call the proper method belonging to
		 * classifier. See the OpenCV documentation.
		 * http://opencv.willowgarage.com/documentation/cpp/objdetect_cascade_classification.html
		 */
		std::vector<cv::Rect> ret;
		cv::Mat m(PREVIEW_IMAGE_HEIGHT,PREVIEW_IMAGE_WIDTH,CV_8U,im(0,0),PREVIEW_IMAGE_WIDTH);
		classifier.detectMultiScale(m,ret,1.1,minNeighbors);
		return ret;
	}

	void SetAcquire(bool a) { acquire = a; }
	bool GetAcquire() { return acquire; }

	void IncNeighbors() { minNeighbors++; }
	void DecNeighbors() { minNeighbors = (minNeighbors>0) ? (minNeighbors-1) : 0; }

private:
	bool acquire;
	int minNeighbors;
	cv::CascadeClassifier classifier;
};



#endif /* MYFACEDETECTOR_H_ */
