424,294 Members | 1,891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,294 IT Pros & Developers. It's quick & easy.

how to detect a face and draw line around it in a picture?

P: 1
Hi. I want to detect a face and draw line exactly around the face to crop it.

I searched a lot and used the EmguCV face detector. but now my code just draw a "rectangle" around the face and if I crop it, I will have a rectangle with a face inside it and it's not useful for me. this is the core of my simple code:

Expand|Select|Wrap|Line Numbers
  1. CascadeClassifier _cascadeClassifier = new CascadeClassifier(Application.StartupPath + "/haarcascade_frontalface_alt_tree.xml");
  2. using (var firstImage = Image.FromStream(saveImageStream))
  3. {
  4.     var bgrImage = new Image(new Bitmap(firstImage));
  5.     Image grayFrame = bgrImage.Convert();
  6.     var faces = _cascadeClassifier.DetectMultiScale(grayFrame, 1.01, 1, Size.Empty);
  7.     foreach (var face in faces)
  8.     {
  9.         bgrImage.Draw(face, new Bgr(Color.BurlyWood), 3);
  10.     }
  11.     Image detectedImage = bgrImage.ToBitmap();
  12.     detectedImage.Save("detectedImage .jpg");
  13. }
the output of this code is a picture with "rectangle" around the face.



the output of this code is a picture with "rectangle" around the face. But how can I detect face and "draw line around the face" like an oval that consist all elements of the face and not anything else?
Jan 15 '19 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.