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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • soroush68
    New Member
    • Jan 2019
    • 1

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

    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:

    Code:
    CascadeClassifier _cascadeClassifier = new CascadeClassifier(Application.StartupPath + "/haarcascade_frontalface_alt_tree.xml");
    using (var firstImage = Image.FromStream(saveImageStream))
    {
        var bgrImage = new Image(new Bitmap(firstImage));
        Image grayFrame = bgrImage.Convert();
        var faces = _cascadeClassifier.DetectMultiScale(grayFrame, 1.01, 1, Size.Empty);
        foreach (var face in faces)
        {
            bgrImage.Draw(face, new Bgr(Color.BurlyWood), 3);
        }
        Image detectedImage = bgrImage.ToBitmap();
        detectedImage.Save("detectedImage .jpg");
    }
    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?
Working...