39 input_img = cv::imread(file_name);
51 const cv::Mat& input_img,
bool fast)
53 std::vector<cv::Rect> front_faces, profile_faces, final_faces;
54 cv::Mat grayscale_img;
55 if( input_img.empty() )
59 cv::cvtColor(input_img, grayscale_img, CV_BGR2GRAY);
60 cv::equalizeHist(grayscale_img, grayscale_img);
63 std::string haar_file_path =
64 "/usr/share/opencv/haarcascades/haarcascade_frontalface_alt.xml";
65 front_faces =
detectFaces( grayscale_img, haar_file_path );
73 haar_file_path =
"/usr/share/opencv/haarcascades/haarcascade_profileface.xml";
74 profile_faces =
detectFaces( grayscale_img, haar_file_path );
90 const std::string& haar_path)
92 std::vector<cv::Rect> faces, final_faces;
95 cv::CascadeClassifier face_cascade;
97 face_cascade.load(haar_path);
99 face_cascade.detectMultiScale(input_img, faces, 1.1, 4);
102 if(faces.size() == 0)
104 face_cascade.detectMultiScale(input_img, faces, 1.1, 3);
108 for(
unsigned int i = 0 ; i < faces.size() ; i++)
110 cv::Rect tmp_rect = faces[i];
113 tmp_rect.width += 20;
114 tmp_rect.height += 20;
115 if(tmp_rect.x < 0 || tmp_rect.y < 0 ||
116 (tmp_rect.x + tmp_rect.width) > input_img.size().width ||
117 (tmp_rect.y + tmp_rect.height) > input_img.size().height)
121 cv::Mat temp_map = input_img(faces[i]);
122 std::vector<cv::Rect> tmp_faces;
123 face_cascade.detectMultiScale(temp_map, tmp_faces, 1.1, 3);
124 if(tmp_faces.size() == 0)
128 final_faces.push_back(faces[i]);
141 const std::vector<cv::Rect> firstFaceVector,
142 const std::vector<cv::Rect> secondFaceVector)
144 std::vector<cv::Rect> final_faces;
146 final_faces = firstFaceVector;
148 final_faces.insert( final_faces.end(), secondFaceVector.begin(),
149 secondFaceVector.end() );
151 int size = final_faces.size();
152 for(
unsigned int i = 0; i < size; i++ )
154 final_faces.push_back( final_faces[i] );
156 groupRectangles( final_faces, 1, 0.2 );
std::vector< cv::Rect > detectFaces(const cv::Mat &input_img, bool fast=false)
Detects faces from a cv::Mat.
std::vector< cv::Rect > identifyUniqueFaces(const std::vector< cv::Rect > firstFaceVector, const std::vector< cv::Rect > secondFaceVector)
Identify unique faces from two sets of faces.
std::vector< cv::Rect > findFaces(std::string file_name, bool fast=false)
Finds faces in an image retrieved from a file URL.
cv::Mat loadImage(std::string file_name)
Loads an image from a file URL.
FaceDetector(void)
Default constructor.