Ask Your Question

Revision history [back]

Keeping in mind that all faces are stored as rectangles you can do the following

// Your detection code
Mat original_image;
vector<Rect> faces;
detectMultiScale(...);

// Loop over detections and store them
for (size_t i=0; i < faces.size(); i++){
   // Define the face you found
   Rect roi = faces[i];
   // Cut it out of the original image
   Mat face = original_image(roi).clone();
   // Store the image
   imwrite("path_to_image_location", face);
}