user994985
user994985

Reputation: 73

faceDetection EmguCV

I having a problem on given green rectangle on the picture.jpg when the picture with 5 people in there. I'm using emguCV v2.2 here the code for the button when i click and fire it.

Image InputImg = Image.FromFile(@"C:\img\Picture.jpg"); 
Image<Bgr,byte> ImageFrame = new Image<Bgr,byte>(new Bitmap(InputImg));

Image<Gray, byte> grayframe = ImageFrame.Convert<Gray, byte>();
 var faces =  grayframe.DetectHaarCascade(haar, 1.4, 4,
                                    HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                                    new Size(25, 25))[0];
foreach (var face in faces)
            {
                ImageFrame.Draw(face.rect, new Bgr(Color.Green), 3);
            }
CamImageBox.Image = ImageFrame;

I expected it should return me the picture.jpg with green rectangle on each faces. But it doesn't . May i know why? is any mistake here?

Thanks

Upvotes: 2

Views: 1877

Answers (2)

Asif Atick
Asif Atick

Reputation: 83

The ScaleFactor should be >1.0 but closer to 1 so you may use 1.04 or 1.01 to have better results, but it will make the process slower. You may increase the minNeighbours so you ma have lesser false positive. And finally use the maxSize parameter to limit the maximum size of the detected box. you may follow the definition of the method

public Rectangle[] DetectMultiScale(
    IInputArray image,
    double scaleFactor = 1.1,
    int minNeighbors = 3,
    Size minSize = null,
    Size maxSize = null
)

Upvotes: 0

V-SHY
V-SHY

Reputation: 4125

 var faces =  grayframe.DetectHaarCascade(haar, 1.4, 4,
                                    HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                                    new Size(25, 25))[0];

You are using scaleFactors = 1.4 and minNeighbors = 4, may be you can adjust these parameters and check the result (scaleFactors = 1.2?)

To prove that your haarcascade is working well, may be you can try to using webcam capture as your picture source?

Private void Form1_load(object sender, EventArgs e)
{
    try
    {
        //capture webcam
        Capture grabber = new Capture();
        //test capture frame
        grabber.QueryFrame();
        //trigger event when application is idle
        Application.Idle += new EventHandler(FrameGrabber);
    }
    catch
    {
        MessageBox.Show("Capture fail to start");
    }
}

void FrameGrabber(object sender, EventArgs e)
{
    Image<Bgr,byte> ImageFrame = grabber.QueryFrame().Resize(320,240,Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
    Image<Gray, byte> grayframe = ImageFrame.Convert<Gray, byte>();
    MCvAvgComp[] faces =  grayframe.DetectHaarCascade(haar, 1.4, 4,
                                    HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                                    new Size(25, 25))[0];
    foreach (MCvAvgComp face in faces)
    {
        ImageFrame.Draw(face.rect, new Bgr(Color.Green), 3);
    }
    CamImageBox.Image = ImageFrame;
}

By the way, return type of grayframe.DetectHaarCascade is MCvAvgComp[][], therefore type of faces in your case is MCvAvgComp[].

Upvotes: 1

Related Questions