我有一个问题,期待有人在我使用Emgu Library检测和面部识别时提供帮助,在面部检测之前我在图片框上绘制一个矩形,目的是我要面对检测和识别位于此矩形内部面部在矩形外面不会检测和识别,我该怎么办呢?请帮帮我。 我的电子邮件:giangnamnam @ gmail.com,非常感谢。
说明:
第1步: Detection and recognition
第2步: I want the result will look like this
这是我的代码:
在图片框上绘制矩形:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Rectangle rect = new Rectangle(90, 80, 160, 160);
using (Pen pen = new Pen(Color.Red, 2))
{
e.Graphics.DrawRectangle(pen, rect);
}
}
面部检测代码:
private void btn_FaceDetection_Click(object sender, EventArgs e)
{
Image<Bgr, byte> imgOriginal = new Image<Bgr, byte>(new Bitmap(pictureBox1.Image));
Image<Gray, Byte> grayFrame = imgOriginal.Convert<Gray, Byte>();
Rectangle[] facesDetected = haar.DetectMultiScale(grayFrame, 1.2, 5, new Size(50, 50), Size.Empty);
if (facesDetected.Length > 0)
{
for (int i = 0; i < facesDetected.Length; i++)
{
facesDetected[i].X += (int)(facesDetected[i].Height * 0.1);
facesDetected[i].Y += (int)(facesDetected[i].Width * 0.15);
facesDetected[i].Height -= (int)(facesDetected[i].Height * 0.2);
facesDetected[i].Width -= (int)(facesDetected[i].Width * 0.2);
// print face to view
Image<Gray, Byte> result = grayFrame.Copy(facesDetected[i]).Convert<Gray, Byte>().Resize(150, 150, INTER.CV_INTER_CUBIC);
result._EqualizeHist();
picb_ViewFace.Image = result.ToBitmap();
// draw rectangle for face
imgOriginal.Draw(facesDetected[i], new Bgr(Color.Green), 2);
}
}
pictureBox1.Image = imgOriginal.ToBitmap();
}