Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
//
// use a cascade classifier to find the face region:
//
cv::String cascade_path("E:\\code\\opencv\\data\\haarcascades\\haarcascade_frontalface_alt.xml");
cv::CascadeClassifier cascade;
bool ok = cascade.load(cascade_path);

Mat gray = ....; // grayscale input image
vector<Rect> faces;
cascade.detectMultiScale(gray, faces, 1.2, 3);

// 
// if it found something, resize the found region:
//
if (faces.size() > 0)
{
     Rect roi = faces[0];
     Mat cropped;
     resize(gray(roi), cropped, Size(300,300));
     imwrite("cropped.png", cropped);
}