[英]Opencv Emgu c# face extraction
到目前為止,我已經設法使我的程序工作和檢測面部現在我想要做的是提取檢測到的區域並顯示在我已經添加的新圖片框中完成后我想將圖片添加到數據庫和比較檢測到的面部與它們。 所以請幫忙
private void ProcessFrame(object sender, EventArgs arg)
{
Image<Bgr, Byte> frame = _capture.QueryFrame();
Image<Gray, Byte> gray = frame.Convert<Gray, Byte>(); //Convert it to Grayscale
//normalizes brightness and increases contrast of the image
gray._EqualizeHist();
//Read the HaarCascade objects
HaarCascade face = new HaarCascade("haarcascade_frontalface_alt_tree.xml");
HaarCascade eye = new HaarCascade("haarcascade_eye.xml");
//Detect the faces from the gray scale image and store the locations as rectangle
//The first dimensional is the channel
//The second dimension is the index of the rectangle in the specific channel
MCvAvgComp[][] facesDetected = gray.DetectHaarCascade(
face,
1.1,
10,
Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_ROUGH_SEARCH,
new Size(20, 20));
foreach (MCvAvgComp f in facesDetected[0])
{
//draw the face detected in the 0th (gray) channel with blue color
frame.Draw(f.rect, new Bgr(Color.Blue), 2);
/*
//Set the region of interest on the faces
gray.ROI = f.rect;
MCvAvgComp[][] eyesDetected = gray.DetectHaarCascade(
eye,
1.1,
10,
Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_ROUGH_SEARCH,
new Size(20, 20));
gray.ROI = Rectangle.Empty;
foreach (MCvAvgComp e in eyesDetected[0])
{
Rectangle eyeRect = e.rect;
eyeRect.Offset(f.rect.X, f.rect.Y);
frame.Draw(eyeRect, new Bgr(Color.Red), 2);
}*/
}
pictureBox1.Image = frame.ToBitmap();Application.DoEvents();
}
private void button1_Click(object sender, EventArgs e)
{
#region if capture is not created, create it now
if (_capture == null)
{
try
{
_capture = new Capture();
}
catch (NullReferenceException excpt)
{
MessageBox.Show(excpt.Message);
}
}
#endregion
if (_capture != null)
{
if (_captureInProgress)
{ //stop the capture
button1.Text = "Start Capture";
Application.Idle -= ProcessFrame;
}
else
{
//start the capture
button1.Text = "Stop";
Application.Idle += ProcessFrame;
}
_captureInProgress = !_captureInProgress;
}
}
我已設法做到這一點,但如果他們遇到同樣的麻煩,我會把這個答案放在幫助他人的地方
gray.ROI = f.rect;
然后你可以為任何圖片框指定灰色,這將只顯示檢測到的區域
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.