Ask Your Question
0

how can i crop the faces from the group photos?

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

usuf gravatar image

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

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
2

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

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

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();
   all_faces.push_back(croppedFace);
}
edit flag offensive delete link more

Comments

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

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

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

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

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

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

Comments

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 -0600 )edit

thanks....

usuf gravatar imageusuf ( 2017-10-16 01:17:08 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 272 times

Last updated: Oct 11 '17