Ask Your Question

how can i crop the faces from the group photos?

asked 2017-10-10 04:22:37 -0500

usuf gravatar image

updated 2017-10-10 04:40:05 -0500

berak gravatar image

Mat img_scene = imread(argv[2], IMREAD_GRAYSCALE);

by using this i can get the photo but how can i crop the each and every faces from this photo?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2017-10-11 06:48:44 -0500

updated 2017-10-11 06:49:17 -0500

Actually if you want to crop faces you will first have to execute a face detector and then store each and every found detection in a vector of Mat elements. Below is a code sample that will do what you look for:

Mat img_scene = imread(argv[2], IMREAD_GRAYSCALE);
CascadeClassifier detector("/data/LBP_frontalface.xml");
Mat temp;
vector<Rect> detections;
equalizeHist(img_scene, temp);
detector.detectMultiScale(temp, detections, 1.1, 3);

vector<Mat> all_faces;
for(size_t i=0; i < detections.size(); i++){
   Mat croppedFace = img_scene(detections[i]).clone();
edit flag offensive delete link more


thanks...for the reply...i did that like ur way

usuf gravatar imageusuf ( 2017-10-16 01:16:13 -0500 )edit

answered 2017-10-10 07:44:22 -0500

supra56 gravatar image
Mat img_scene = imread(argv[2], IMREAD_GRAYSCALE);
namedWindow("image", CV_WINDOW_FREERATIO);
imshow("image", img_scene);

Rect croppedRectangle = Rect(181, 225, 400, 50);
Mat CroppedImage = img_scene(croppedRectangle);

namedWindow("Cropped", CV_WINDOW_FREERATIO);
imshow("Cropped", CroppedImage);
edit flag offensive delete link more


This will only work if you already know the locations of the faces beforehand. Else you will need to look for them first.

StevenPuttemans gravatar imageStevenPuttemans ( 2017-10-11 06:50:06 -0500 )edit


usuf gravatar imageusuf ( 2017-10-16 01:17:08 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-10-10 04:22:37 -0500

Seen: 122 times

Last updated: Oct 11 '17